0
我正在尝试基于Dan Abramov here的建议来实现redux重置状态操作。我设置我的减速器和存储,像这样:Redux - 重置状态
Index.js:
import {applyMiddleware,createStore} from 'redux';
import combineReducers from './reducers/index';
import {wrapStore,alias} from 'react-chrome-redux';
import thunk from 'redux-thunk';
import aliases from './aliases/aliases';
const combineAppReducers = (state, action) => {
if (action.type === 'LOG_OUT') {
state = undefined;
}
return combineReducers(state, action)
}
const middlewares = [alias(aliases), thunk];
const store = createStore(combineAppReducers,applyMiddleware(...middlewares));
wrapStore(store, {
portName: 'example'
});
Reducers.js:
import {combineReducers} from 'redux';
import userAuthReducer from './userAuthReducer';
import manageTeamsReducer from './manageTeamsReducer';
function lastAction(state = null, action) {
return action;
}
export default combineReducers({
userAuthReducer,manageTeamsReducer,lastAction
});
看起来好像我已经正确设置好一切,但应用程序没有重置状态,任何人都可以发现我出错的地方吗?
这里是它的另一篇文章,我更紧随其后:
https://medium.com/@agungsantoso/how-to-reset-the-state-of-a-redux-store-7f9d85b190bc
你试过设置状态到一个空对象?像'state = {}'? – lumio
你还得到什么错误? – lumio
我认为这不是最好的方法,但是,您可以将您的状态恢复为第一个调度值:'@@ INIT'操作。 – Hitmands