我使用 React + Redux + Webpack + WebpackDevserver.一旦热启动器启动,我的所有减速器都将重置为初始状态.
我能以某种方式保持我的减速器处于实际状态吗?
我的Webpack配置包含:
entry: [ "./index.jsx" ], output: { filename: "./bundle.js" }, module: { loaders: [ { test: /\.js|\.jsx$/, exclude: /node_modules/, loaders: ["react-hot","babel-loader"], } ] }, plugins: [ new webpack.HotModuleReplacementPlugin() ]
我的减速器统计数据:
const initialState = { ... } export default function config(state = initialState, action) { ...
我只是通过以下方式启动我的Webpack Dev-Server:
"start": "webpack-dev-server",
Juho Vepsälä.. 15
假设Babel 6,你需要做一些事情:
import {createStore} from 'redux'; import rootReducer from '../reducers'; export default function configureStore(initialState) { const store = createStore(rootReducer, initialState); if(module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers/index').default; store.replaceReducer(nextReducer); }); } return store; }
您可以在我的redux演示中看到该方法的实际应用.
假设Babel 6,你需要做一些事情:
import {createStore} from 'redux'; import rootReducer from '../reducers'; export default function configureStore(initialState) { const store = createStore(rootReducer, initialState); if(module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers/index').default; store.replaceReducer(nextReducer); }); } return store; }
您可以在我的redux演示中看到该方法的实际应用.