错误消息 -
提供商不支持动态更改商店。您很可能会看到此错误,因为您已更新到Redux 2.x和React Redux 2.x,它们不再自动热重新加载Reducer。有关迁移说明,请参阅https://github.com/reactjs/react-redux/releases/tag/v2.0.0。
configureStore.js -
import { createStore,applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import reducers from './reducers';
export default function configureStore(initialState) {
const store = createStore(reducers,{},applyMiddleware(ReduxThunk));
if (module.hot) {
// console.log("in module.hot");
console.log(reducers);
module.hot.accept( () => {
const nextRootReducer = require('./reducers/index').default;
store.replaceReducer(nextRootReducer)
});
}
return store;
}
App.js -
render(){
const store = configureStore();
return(
<Provider store = {store}>
<Container>
<Login/>
</Container>
</Provider>
参考 -
视频 - https://www.youtube.com/watch?v=t2WXfAqLXJw
github - https://github.com/reactjs/react-redux/releases/tag/v2.0.0
视频中的解决方案已实施
答案 0 :(得分:12)
您已经实现了在模块加载热量时更改reducer的要求,但您仍在尝试为每个渲染创建一个新的存储。
相反,请尝试将configureStore()
电话移至组件外部。
const store = configureStore();
class App extends React.Component {
render(){
return(
<Provider store = {store}>
<Container>
<Login/>
</Container>
</Provider>