当前位置: 首页 > 工具软件 > Clear Toolkit > 使用案例 >

redux clear store

郭乐湛
2023-12-01

redux clear store

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);

 类似资料:

相关阅读

相关文章

相关问答