rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.95k stars 865 forks source link

Clear store on onClick (not on logout) #1058

Open ravimantra opened 5 years ago

ravimantra commented 5 years ago

I need to clear store on onClick event. Below is my "configureStore".

const persistedReducer = persistReducer(persistConfig, rootReducer(history));

export default function configureStore (preloadedState) { const store = createStore( persistedReducer, // root reducer with router state preloadedState, compose( applyMiddleware( routerMiddleware(history), // for dispatching history actions thunk, reduxImmutableStateInvariant(), logger ) ) ) const persistor = persistStore(store) return { store, persistor } }

ghost commented 5 years ago

You can, for example, try to pass the persistor along with the store down to the components tree. Then inside onClick event use persistor's purge method, which dispatches PURGE action.