question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configuring sessionStorage persist state

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
geekyarjuncommented, Oct 31, 2019

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’;

2reactions
syedshahidashiqalicommented, Apr 25, 2022

what if i want to make my storage dynamic like the default for some reducers and session for some reducers like auth ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to persist to both localStorage and sessionStorage at the ...
My first question is if my client side view and approach is correct or not. If it is, how can I update my...
Read more >
Persisting Data with Redux, Thunk, Session Storage in React ...
In the above code, our LoginReducer by default receives two arguments namely state and action. The state is the current store state while...
Read more >
Persist State | Elf | A Reactive Store with Magical Powers
The persistState() function gives you the ability to persist some of the app's state, by saving it to localStorage/sessionStorage or anything that implements ......
Read more >
How to Persist React State in Local Storage - Felix Gerschau
Unlike localStorage , sessionStorage clears all data when the browser is closed. However, it does persist when the user refreshes the page or ......
Read more >
Persist state with Redux Persist using Redux Toolkit in React
Setting up React; Persisting state with Redux Persist ... storage engines like sessionStorage and Redux Persist Cookie Storage Adapter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found