使用多个reducer注销时如何重置状态

时间:2019-07-02 07:52:30

标签: typescript redux

当我有多个异径管时,如何重设状态?我看到了各种示例,How to reset the state of a Redux store?。如下。

const appReducer = combineReducers({
  /* your app’s top-level reducers */
})

const rootReducer = (state, action) => {
  if (action.type === 'USER_LOGOUT') {
    state = undefined
  }

  return appReducer(state, action)
}

我很困惑如何进行。拥有

时如何使用以下方法重置状态

我的rootReducer看起来像这样:

export interface IState {
  userReducer: IUserState;
  sessionReducer: ISessionState;
  authenticateReducer: IAuthenticateState;
  articlesReducer: IArticlesState;
}

export const reducers = combineReducers<IState>({
  userReducer,
  sessionReducer,
  authenticateReducer,
  articlesReducer  
});

仅提供一个状态示例(我为IUserState提供),因为其他状态在初始化时具有相同的体系结构。

export interface IUserState {
  user: IUserEntity;
  alert?: IAlertEntity;
  errors: IErrorsEntity;
}
export const initialState: IUserState = {
  errors: EmptyErrors(),
  alert: EmptyMessage(),
  user: EmptyUser()
};

如何重置我的状态,什么是最佳解决方案?

1 个答案:

答案 0 :(得分:0)

我在注销onClick时使用location.reload()