除了几个值之外,重置Redux商店的状态?

时间:2018-05-23 13:12:33

标签: react-redux

我想在注销时重置redux商店的状态而不删除某些值。 我提到了这个链接:How to reset the state of a Redux store?。 注销后如何在商店中保留一些完整的值。

1 个答案:

答案 0 :(得分:0)

This答案可以稍加修改,以适合您的情况。

您可以使用merge()方法清除特定属性,同时保留其他属性,而不是完全设置state = undefined;

     const rootReducer = (state, action) => {
      if (action.type === 'USER_LOGOUT') {
        return state.merge({
            value1: undefined,
            value2: undefined,
            ...
        });
      }

      return appReducer(state, action)
    }