Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React JS: Component Not Exported

I have below folder structure of my project :-

enter image description here

Within GlobalStore.js , I have code ->

import React from 'react'

const GlobalContext=React.createContext();
const GlobalProvider=GlobalContext.Provider;
const GlobalConsumer=GlobalContext.Consumer;


export default {GlobalProvider,GlobalConsumer}

In App.js I have below code -

import logo from './logo.svg';
import './App.css';
import Login from './Components/Login';
import { store } from "./GlobalStorage/store";
import   {GlobalProvider,GlobalConsumer} from "./GlobalStore";
function App() {
  return (
    <div className="App">
      <GlobalProvider value={store}> 
     <Login></Login>
     </GlobalProvider>
    </div>
  );
}

export default App;

Though I have exported GlobalProvider from GlobalStore.js , Application is throwing below error -

Failed to compile.

./src/App.js
Attempted import error: 'GlobalProvider' is not exported from './GlobalStore'.
like image 670
C Sharper Avatar asked Sep 04 '26 19:09

C Sharper


1 Answers

You are exporting an object with properties GlobalProvider and GlobalConsumer as the default export from GlobalStore.js. Remove the default keyword and it will work as expected with regular named exports.

export { GlobalProvider, GlobalConsumer };
like image 86
Tholle Avatar answered Sep 07 '26 08:09

Tholle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!