How to reset the state of a Redux store?

前端 未结 30 1916
陌清茗
陌清茗 2020-11-22 06:20

I am using Redux for state management.
How do I reset the store to its initial state?

For example, let’s say I have two user accounts (u1 and

30条回答
  •  渐次进展
    2020-11-22 06:26

    Combining the approaches of Dan, Ryan and Rob, to account for keeping the router state and initializing everything else in the state tree, I ended up with this:

    const rootReducer = (state, action) => appReducer(action.type === LOGOUT ? {
        ...appReducer({}, {}),
        router: state && state.router || {}
      } : state, action);
    

提交回复
热议问题