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

Aranya Dream

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")
);
Viet

You import store wrong way:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TypeError: store.getState is not a function in react-redux

react-redux : TypeError: store.getState is not a function

TypeError: _this.store.getState is not a function when using connect from Redux

store.getState is not a function Redux-persist

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined

TypeError: getState is not a function when adding middleware to Redux

Uncaught TypeError: store.getState is not a function

React Native TypeError store.getState is not a function

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem?

Redux: Calling store.getState() in a reducer function, is that an anti pattern?

TypeError: getState is not a function in redux when trying to pass token

I am getting this error: TypeError: store.getState is not a function

store.getState is not a function

Redux - Undefined is not an object (evaluating 'store.getState')

Is correct to use store.getState() in a redux container?

Redux Persist TypeError: store.dispatch is not a function

TypeError: undefined is not an object (evaluating 'store.getState')

"Cannot read property 'getState' of undefined" when creating redux mock store

Redux Testing - getState() TypeError: Cannot read property 'startDateIndex' of undefined

Redux/toolkit TypeError: Cannot read properties of undefined (reading 'getState')

TypeError: Cannot read property ‘getState’ of undefined in Redux Tookit

state.getState() is not a function while updating to redux 4

Binding a redux store to a function

TypeError: Object(...) is not a function (redux)

getState in redux-saga?

Redux getState in action not working

Redux / Angular getState() is undefined

How to getState() in Redux Toolkit

Unable to getState in redux actions