2

I have created a redux store below, the only thing I want to clear the redux store when user logout from the application, so store having the latest and updated data of currently logged user.

import { createStore, applyMiddleware, compose } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import rootReducer from './Reducers';
import { sessionService } from 'redux-react-session';
import thunk from 'redux-thunk';

const persistedReducer = persistReducer({ key: 'root', storage }, rootReducer);

const composeEnhancers =
  (typeof window !== 'undefined' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
  compose;

export const store = createStore(
  persistedReducer,
  composeEnhancers(
    applyMiddleware(thunk)
  )
);
export const persistor = persistStore(store);
sessionService.initSessionService(store);

The above snippet I wrote to create the store using redux persist please suggest

jack
  • 112
  • 1
  • 8
  • You can just have an action for clearing the data and dispatch it in your logout function – coglialoro Mar 30 '22 at 07:38
  • 2
    Does this answer your question? [How to reset the state of a Redux store?](https://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store) – deepak thomas Mar 30 '22 at 07:43

0 Answers0