redux replaceReducer似乎不适用于HMR

时间:2017-12-02 16:33:44

标签: redux react-hot-loader

我使用react-hot-loader配置开发环境,HMR正常工作。我为redux添加了以下配置

if (module.hot) {
   // Enable Webpack hot module replacement for reducers
   module.hot.accept('../reducers', () => {
     console.log('reducers change')
     const nextReducer = require('../reducers').default
     store.replaceReducer(nextReducer)
  })
}

当我更改reducer文件时,module.hot.accept处理程序工作,[HMR]似乎获得成功信息

[HMR] connected
[HMR] bundle rebuilding
[HMR] bundle rebuilt in 405ms
[HMR] Checking for updates on the server...
reducers change
[HMR] Updated modules:
[HMR]  - ./src/reducers/testReducer.js
[HMR]  - ./src/reducers/index.js
[HMR] App is up to date. 

但是状态没有改变,它的价值仍然是初始值。

1 个答案:

答案 0 :(得分:0)

在你的configuration.js中,你导入了'./reducers/index.js'吗?