下一个 redux 包装器出现无法读取未定义的属性 'getState' 的错误
Posted
技术标签:
【中文标题】下一个 redux 包装器出现无法读取未定义的属性 \'getState\' 的错误【英文标题】:Next redux wrapper arise error of Cannot read property 'getState' of undefined下一个 redux 包装器出现无法读取未定义的属性 'getState' 的错误 【发布时间】:2020-04-22 13:50:42 【问题描述】:在这个项目中,我将下一个 js 库与 redux 一起使用,并且我还使用下一个 redux 包装器我按照下一个 redux 包装器文档中提到的方式执行所有操作,但它在这里无法正常工作,它会出现 getState of undefined 错误,因为我显示在上图中。所以在这里我调试了所有代码,但我找不到出现这个错误的地方。 我在下面列出了我在我的 react js 文件中完成的代码。
_app.js
import React from "react";
import App from "next/app";
import Provider from "react-redux";
import withRedux from "next-redux-wrapper";
import makeStore from ".././src/config/store";
class ConsoleApp extends App
/**
* Render View
*/
render()
const Component, pageProps, store = this.props;
return (
<Provider store=store>
<Component ...pageProps />
</Provider>
);
export default withRedux(makeStore)(ConsoleApp);
root-reducer.js
/**
* Import Dependencies
*/
import combineReducers from "redux-immutable";
/**
* Import Reducers
* All Reducers used in the App must be declared here!
*/
import GraphicReducer from "../modules/Graphics/reducer";
import UserReducer from "../modules/User/reducer";
/**
* Combine the Reducers
*/
const reducers = combineReducers(
graphics: GraphicReducer,
user: UserReducer
);
/**
* Export the combined Reducers
*/
export default reducers;
store.js
import createStore, applyMiddleware from "redux";
import composeWithDevTools from "redux-devtools-extension";
import reducers from "./root-reducer";
import thunk from "redux-thunk";
/**
* Prepare the Redux Store
*/
const composedMiddlewares = applyMiddleware(thunk);
const storeEnhancers = composeWithDevTools(
name: "React-node-test"
)(composedMiddlewares);
const makeStore = () =>
createStore(reducers, storeEnhancers);
;
export default makeStore;
【问题讨论】:
【参考方案1】:请使用下面的 sn-p,因为您忘记了 return createStore(reducers, storeEnhancers);
const makeStore = () =>
return createStore(reducers, storeEnhancers);
;
【讨论】:
以上是关于下一个 redux 包装器出现无法读取未定义的属性 'getState' 的错误的主要内容,如果未能解决你的问题,请参考以下文章
我在 react-redux 小测试中得到“无法读取未定义的属性 'cart'”
使用redux时无法在反应js中读取未定义的属性(读取'map')
React / Redux - 无法读取未定义的属性“XXX”
Redux TypeError:无法读取未定义的属性“列表”