我正在尝试进行redux-persist热装。
以下是说明:
https://github.com/rt2zz/redux-persist/blob/master/docs/hot-module-replacement.md
我试图做到这一点,并且它不会热装。
我已经在accept函数中设置了调试器和console.log,但是它没有中断或记录(不确定webpack是否会忽略或删除它们):
export default () => {
if (module.hot) {
debugger; // eslint-disable-line
module.hot.accept('./reducers', () => {
debugger; // eslint-disable-line
// This fetch the new state of the above reducers.
const nextRootReducer = require('./reducers').default; // eslint-disable-line
console.log(nextRootReducer);
store.replaceReducer(
persistReducer(persistConfig, nextRootReducer),
);
});
}
return { store, persistor };
};
这是我的完整配置:
/* globals require */
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import rootReducer from './reducers';
import rootSaga from './sagas/sagas';
const sagaMiddleware = createSagaMiddleware();
const persistConfig = {
key: 'root',
storage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const createStore = () => reduxCreateStore(
persistedReducer,
composeWithDevTools(
applyMiddleware(sagaMiddleware),
),
);
const store = createStore();
const persistor = persistStore(store);
sagaMiddleware.run(rootSaga);
export default () => {
if (module.hot) {
debugger; // eslint-disable-line
module.hot.accept('./reducers', () => {
debugger; // eslint-disable-line
// This fetch the new state of the above reducers.
const nextRootReducer = require('./reducers').default; // eslint-disable-line
console.log(nextRootReducer);
store.replaceReducer(
persistReducer(persistConfig, nextRootReducer),
);
});
}
return { store, persistor };
};
我必须做些不同的事情吗?
如果不对默认配置进行任何相关修改,我正在使用gatsby的话。