Redux-persist: Clear stored state from browser console

Created on 18 Jan 2018  路  5Comments  路  Source: rt2zz/redux-persist

Hello there,

I've being using this awesome module for some days, and I'm facing a problem while developing a project which I couldn't find an answer in the docs or stackoverflow.

I'd like to know if it's possible to someway clear the stored state from the browser console. Since I'm still developing the app, we're doing changes to the state structure very often, and seeing that there's already a stored state, when the app loads again we only get the outdated state which was stored. Then would be very convenient for us to find a way to clear the whole stored state some times to order to check the new changes to the redux state.

I tried the basic localStorage.clear but once the persist/REHYDRATE is dispatched, the old stored state strikes again.

I'm sorry if I missed a very basic point about it.

Thanks,

Most helpful comment

You can use the functions persistor.flush() to enforce writing the latest redux data to local storage, or persistor.purge() to clear the local storage (note that it leaves the redux data intact).

In order to get access to the persistor we the persistor to the appropriate component from the router.

All 5 comments

You can use the functions persistor.flush() to enforce writing the latest redux data to local storage, or persistor.purge() to clear the local storage (note that it leaves the redux data intact).

In order to get access to the persistor we the persistor to the appropriate component from the router.

@ChrisLahaye thank you for your reply.

I'll try to export the persistor object someway to get access to it into the browser console and be able to call both methods.

you can access it from the browser console by exposing it as a window variable

i.e.

window.persistor = persistor

I'm getting window.persistor is undefined... 馃

Was this page helpful?
0 / 5 - 0 ratings