i am using React flux for state management. How can I reset the store to its initial state?
For example, let’s say I have two user accounts (user1 and user2).
Imagine the following sequence of events:
User1 logs into the app and does something, so we cache some data in the store. User1 logs out. User2 logs into the app without refreshing the browser. At this point, the cached data will be associated with user11, and I would like to clean it up.
How can I reset the React Flux store to its initial state when the first user logs out?
On user logout action you can dispatch an event to reset data. Like -
store.dispatch({
type: types.RESET_USER_STATE,
});
and then in the reducer reset the state like -
case types.RESET_USER_STATE:
return Object.assign({}, state, initialStateHere );