Open aravi365 opened 3 years ago
I think this is the same bug as described in https://github.com/rt2zz/redux-persist/issues/1294
It seems redux-persist treats this use case as if initial state is being passed (you are really reusing the initialState logic when you clear the store this way). That is why it will not persist the changes to the reducer after undefined is passed in as state, since it is missing a _persist key in the state.
You will need to call persistor.purge()
manually. To avoid circular dependancies, have a resetState function in your store.js file:
export const store = createStore(rootReducer, composeMiddlewares);
export const persistor = persistStore(store);
export const resetStore = async () => {
await persistor.purge();
store.dispatch(resetStore());
await persistor.flush();
};
Then import that method wherever needed and call it.
Data stored initially gets replaced with new data after logout and when app is restarted or refreshed the initial stored data is retrieved back to reducer instead of the second set of stored data or reducer initial states.
Here is my store config code: