简体   繁体   English

TypeError: store.getState 不是 function (redux)

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

I keep on getting this error:我不断收到此错误:

TypeError: store.getState is not a function类型错误:store.getState 不是 function

I think the problem might be in my store.js but I'm not really sure where.我认为问题可能出在我的 store.js 但我不确定在哪里。

Below are the codes:以下是代码:

root reducer.js root reducer.js

import { combineReducers } from "redux";

import userReducer from "./User/userReducer";

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

root saga.js根 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商店.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索引.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:您以错误的方式导入store

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反应 Redux:TypeError:store.getState 不是 function - React Redux : TypeError: store.getState is not a function 类型错误:store.getState 不是函数 React-redux - TypeError: store.getState is not a function React-redux TypeError:store.getState不是函数。 (在“ store.getState()”中,“ store.getState”未定义 - TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined store.getState 不是 function react-redux - store.getState is not a function react-redux React Native TypeError store.getState不是一个函数 - React Native TypeError store.getState is not a function TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined 我该如何解决这个问题? - TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem? Redux:在reducer函数中调用store.getState(),这是一种反模式吗? - Redux: Calling store.getState() in a reducer function, is that an anti pattern? 我收到此错误:TypeError: store.getState is not a function - I am getting this error: TypeError: store.getState is not a function Provider.js:20 Uncaught TypeError: store.getState is not a function - Provider.js:20 Uncaught TypeError: store.getState is not a function React store.getState 不是函数 - React store.getState is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM