redux replaceReducer seems not work in HMR

496 Views Asked by At

I've configured a development environment with react-hot-loader. HMR is working normally and I've added the configuration below for 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)
  })
}

when I change the reducer file, module.hot.accept handler works and [HMR] seems to get the succeess info

[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. 

but the state is not changing, it's value is still the initial one.

1

There are 1 best solutions below

0
On

in you configuration.js ,have you import './reducers/index.js'?