本文主要是介绍Redux - Unhandled Rejection (Error): You may not call store.getState() while the reducer is executin,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Unhandled Rejection (Error): You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.
是不是头皮发麻。。。哈哈
其实这不是你的代码问题,是Redux Devtools的BUG
为了使用redux-thunk和Redux Devtools是不是在生成store.js时写了如下代码
// const composeEnhancers =
// typeof window === 'object' &&
// window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
// window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// }) : compose;// const enhancer = composeEnhancers(
// applyMiddleware(thunk),
// );
我们改成(这样不使用Redux Devtools 或者试试第二种)
const enhancer = applyMiddleware(thunk);
const store = createStore(reducer, enhancer)
const store = createStore(reducers, compose(applyMiddleware(thunk),window.devToolsExtension?window.devToolsExtension():f =>f
) )
这篇关于Redux - Unhandled Rejection (Error): You may not call store.getState() while the reducer is executin的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!