我很难让减速器热插拔。
我正在使用Webpack和react-transform- hmr。这样,保存时所有CSS和组件都会被热加载,但是当我尝试使用另一种类型(最著名的是reducer)时,它将告诉我进行完全刷新。
react-transform- hmr
我发现这是因为我需要显式重新加载reducers并接受事件。我在我的代码中正在做的事情store.js:
store.js
if(module.hot) { module.hot.accept('./reducers/', () => { const nextRootReducer = require('./reducers/index'); store.replaceReducer(nextRootReducer); }); }
reducers/index 出口根减速器。
reducers/index
但是现在当我运行它时,它仍然告诉我,[HMR] Cannot check for update (Full reload needed并且还说错误[HMR] TypeError: currentReducer is not a function
[HMR] Cannot check for update (Full reload needed
[HMR] TypeError: currentReducer is not a function
所以-我需要一些帮助以使其正常工作。该代码位于https://github.com/wesbos/Simple- Redux,您可以通过执行以下操作来重现它:
npm install
npm start
posts.js
我没有仔细看,但我最好的猜测是这是问题。 Babel 6不再尝试将ES6默认导出为的结果module.exports。
module.exports
所以代替
const nextRootReducer = require('./reducers/index');
你可能想要
const nextRootReducer = require('./reducers/index').default;
匹配Babel 6输出以进行ES6默认导出。