使Redux减速器和其他非组件可热装载

wes*_*bos 9 javascript flux reactjs webpack redux

我很难让减压器变热.

我正在使用Webpack和react-transform-hmr.有了这个,当我保存时,所有的CSS和组件都是热加载的,但是当我尝试使用其他类型的类型时 - 最明显的是减速器 - 它会告诉我进行全面刷新.

我发现这是因为我需要明确地重新加载reducers并接受事件.我在我的代码中使用的是store.js:

if(module.hot) {
  module.hot.accept('./reducers/', () => {
    const nextRootReducer = require('./reducers/index');
    store.replaceReducer(nextRootReducer);
  });
}
Run Code Online (Sandbox Code Playgroud)

reducers/index 导出根减速器.

但是现在当我运行它时它仍然告诉我[HMR] Cannot check for update (Full reload needed并且还有错误说[HMR] TypeError: currentReducer is not a function

所以 - 我需要一些帮助才能让它发挥作用.代码可以在https://github.com/wesbos/Simple-Redux上找到,你可以通过这样做来重现它:

  1. npm install
  2. npm start
  3. 在浏览器中打开localhost:3000
  4. 编辑减速器 - 打开posts.js并将第6行的数字更改为其他任何内容

Dan*_*mov 18

我没有密切关注,但我最好的猜测就是这个问题.
Babel 6不再试图使ES6默认导出结果module.exports.

而不是

const nextRootReducer = require('./reducers/index');
Run Code Online (Sandbox Code Playgroud)

你可能想要的

const nextRootReducer = require('./reducers/index').default;
Run Code Online (Sandbox Code Playgroud)

它与Babel 6输出匹配,用于ES6默认导出.