redux 没有内置清除 store 的功能,需要手动实现,以下是其中一个方案
const addClearToReducer =
(reducer: any) => (state: {}, action: { type: string; payload: any }) => {
if (action.type === CLEAR) {
return {};
} else {
return reducer(state, action);
}
};
const reducers = Object.entries({
userInfo
}).reduce((tmp, next) => {
tmp[next[0]] = addClearToReducer(next[1]);
return tmp;
}, {} as ReducersMapObject<any, any>);
export const rootReducers = combineReducers(reducers);