0

I want to reset the state of the redux store on logout without removing some values. I referred to this link : How to reset the state of a Redux store?. How can i keep some values intact in the store after logout.

Meenakshi
  • 79
  • 1
  • 7

1 Answers1

0

This answer can be slightly modified to suit your case.

Instead of setting state = undefined; completely, you can use merge() methods to clear only specific properties while retaining the others.

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

      return appReducer(state, action)
    }