react+redux热更新时 redux警告不支持store热更新
按照GitHub中issue中的介绍 redux2.0后将不支持热更新,兼容方案是使用replaceReducer的方式,照着做后,状态确实可以保存,但控制台依然报错,而且仅在第一次hrm的时候报错,后面再hrm的时候不在报错了,请问如何使第一次也不报警告呢?
报错信息:
<Provider> does not support changing `store` on the fly. It is most likely that you see this error because you updated to Redux 2.x and React Redux 2.x which no longer hot reload reducers automatically. See https://github.com/reduxjs/react-redux/releases/tag/v2.0.0 for the migration instructions.```
const store = createStore(
connectRouter(history)(makeRootReducer()),
preloadedState,
composeEnhancers(applyMiddleware(...middlewares)),
);
store.asyncReducers = {}
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept("./reducers", () => {
const nextRootReducer = require("./reducers").default;
store.replaceReducer(nextRootReducer(store.asyncReducers));
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论