search

Home  >  Q&A  >  body text

javascript - A piece of code for react hot loading

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

I don’t know what this code has to do with hot loading and redux, please explain it

漂亮男人漂亮男人2699 days ago811

reply all(1)I'll reply

  • typecho

    typecho2017-06-26 10:55:03

    This is so that the status of redux can continue to remain unchanged during the relevant code.

    For example: after a count field in redux is operated, the value is 2. If you don’t write that code, the count will become the initial value after the page is hot updated. This is my impression.

    reply
    0
  • Cancelreply