0

I'm trying to import my redux store into a non react component, so that I can dispatch some actions to it. But when I import store it just gives me this error:

"export 'store' was not found in '../../store'

And store remains undefined where I've imported it.

It's definitely there and the path is right so I can't figure out what I'm doing wrong.

I've tried what it says here and a few other things but still no luck: "export 'store' was not found in '../store'

Here's my store:

import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunk from "redux-thunk";
import rootReducer from "./reducers";

const initialState = {};

const middleware = [thunk];

const store = createStore(
  rootReducer,
  initialState,
  composeWithDevTools(applyMiddleware(...middleware))
);

export default store;

Then I'm importing it like this:

import { store } from "../../store";
jbflow
  • 384
  • 1
  • 11
  • 3
    You've exported the store as a default export, so the `store` named export doesn't exist. Use `import whateverName from "../../store";` – Emile Bergeron Aug 17 '20 at 19:37
  • And the [difference between a default export and a named export](https://stackoverflow.com/q/33611812/1218980). – Emile Bergeron Aug 17 '20 at 19:41
  • Thank you, I will look at these. The code base I've got is from a tutorial that I've started adding to and adapting, so I'm not sure if the store needs to be exported as a default export or not. I don't think it gets imported anywhere else. – jbflow Aug 17 '20 at 20:07
  • 1
    So I'd just need to import it without the braces? Trying that throws up errors to do with my prop types, so will have to look into that now. Thanks for your help. – jbflow Aug 17 '20 at 20:12
  • Yes, as a default export makes sense and is totally fine for the store, just importing it without the braces would be the correct way to fix the import problem. – Emile Bergeron Aug 17 '20 at 20:21

0 Answers0