简体   繁体   中英

TypeError: store.getState is not a function (redux)

I keep on getting this error:

TypeError: store.getState is not a function

I think the problem might be in my store.js but I'm not really sure where.

Below are the codes:

root reducer.js

import { combineReducers } from "redux";

import userReducer from "./User/userReducer";

export default combineReducers({
  user: userReducer,
});

root saga.js

import { all, call } from "redux-saga/effects";

import userSaga from "./User/user.saga";

//generator function
export default function* rootSaga() {
  //to pass our sagas
  yield all([call(userSaga)]);
}

store.js

import { createStore, applyMiddleware } from "redux";
import logger from "redux-logger";
import thunk from "redux-thunk";
import createSagaMiddleWare from "redux-saga";
import { persistStore } from "redux-persist";

import rootReducer from "./rootReducer";
import rootSaga from "./rootSaga";

const sagaMiddleware = createSagaMiddleWare();
export const middleWares = [thunk, sagaMiddleware, logger];

export const store = createStore(rootReducer, applyMiddleware(...middleWares));
sagaMiddleware.run(rootSaga);

//----
export const persist = persistStore(store);

export default { store, persist };

index.js

import { BrowserRouter } from "react-router-dom";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { Provider } from "react-redux";
import store from "./Redux/store";

ReactDOM.render(
  <React.StrictMode>
    <Provider store={store}>
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </Provider>
  </React.StrictMode>,
  document.getElementById("root")
);

You import store wrong way:

import { store } from "./Redux/store";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM