Redux-persist: Configuring sessionStorage persist state

Created on 22 Jun 2017  路  8Comments  路  Source: rt2zz/redux-persist

I'm trying to figure out what I've been doing wrong for a while.

So, I implemented react-persist by passing the createStore the autoHydrate() along with my middleware. And then tried to call it to persist into the sessionStorage like

  persistStore(store, {
    whitelist: ['locale', 'auth'],
    storage: sessionStorage
  });

trying to make only the locale and auth nodes of my state to persist into it. All I can get is the full state persisted into the localStorage instead ..

What am I doing wrong?

On a side question .. if I finally only make it so those two nodes are stored, should I just include the reducer entry looking for the REHYDRATE action.type into the reducers actually using those nodes? Or is it even better to create a new reducer to be looking for this one and get all the payload in?

Thank you in advance

Most helpful comment

Yes, it is possible. I am using "redux-persist": "^6.0.0", and I can persist data in session storage by importing storage like this:
import storage from 'redux-persist/lib/storage/session';

All 8 comments

Shameless bump .. can you offer some advice, please?

Furthermore, if I set it to storage: localStorage it's not working either. It's only working when I don't pass any storage value on the config when I can get those two whitelisted nodes to persist.

@qborreda, you need to use import { asyncLocalStorage, asyncSessionStorage } from "redux-persist/storages"

Thanks @rrivem - will try that, although I made it work finally, with just the whitelist config part.

So, would it be

persistStore(store, {
    whitelist: ['locale', 'auth'],
    storage: asyncSessionStorage
  });

like this?
(Probably missed a version update here)

Cannot find module "redux-persist/storages"

that was v4, use import storage from 'redux-persist/lib/storage'for v5

is redux-persist session storage possible??

Yes, it is possible. I am using "redux-persist": "^6.0.0", and I can persist data in session storage by importing storage like this:
import storage from 'redux-persist/lib/storage/session';

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ucarion picture ucarion  路  4Comments

ejbp picture ejbp  路  3Comments

thenewt15 picture thenewt15  路  3Comments

jrmdayn picture jrmdayn  路  4Comments

umairfarooq44 picture umairfarooq44  路  3Comments