DEV Community

Redux-persist (v6) in detail (React)

Vikrant Bhat on July 04, 2020

Whenever you reload your app, the javascript process has nothing in memory. You will have to re-initialize state, and maybe set some basic state ...
Collapse
 
deepseafishdev profile image
DeepSeaFish-Dev •

Just a quick note, you pass the persistReducer instead of your newly created persistedReducer here:

const store = createStore(
    persistReducer, // pass the persisted reducer instead of rootReducer to createStore
    applyMiddleware() // add any middlewares here
)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gajen007 profile image
Gajen Dissanayake •

Thanks Bro,

I assumed there is a typo mistake in Step 2

//pass the persisted reducer instead of rootReducer to createStore//

So the first argument of configureStore method should be persistedReducer, not persistReducer...

Is it true ?

Collapse
 
ssameghini profile image
Sebastián Sameghini •

Hi!
What if I only want to persist the store after a user has authenticated?
For example, when someone visits my page an authentication check is made (token then session restored), but if no session is found, the page redirects to /login. PersistGate would delay the rendering of this page until a persist process completes, preventing anyone without credentials to access the page (in practice, no one access).

Collapse
 
bhatvikrant profile image
Vikrant Bhat •

Dispatch your action only after verification

Collapse
 
abhishek150190 profile image
Abhishek150190 •

Can we change the default storage of redux persist to sessionStorage instead of localStorage?

Collapse
 
tmitkov profile image
Tihomir Mitkov •

Wouldn't this be useless? I mean the sessionStorage gets cleared when the tab gets closed, the same behaviour would occure if you simply use redux without redux-persist?

Collapse
 
bhatvikrant profile image
Vikrant Bhat •

+1 on that

Collapse
 
daniilryb profile image
Daniil Rybakov •
Collapse
 
zahirhasheminas profile image
zahir hashemi nasab •

so Great article
tnx alot bro

Collapse
 
bhatvikrant profile image
Vikrant Bhat •

Glad to help buddy! 😁

Collapse
 
davidromanhub profile image
David Roman •

thanks alot! was very helpfull!

Collapse
 
bhatvikrant profile image
Vikrant Bhat •

My Pleasure buddy! 😁

Collapse
 
hamzaazeem97 profile image
HamzaAzeem97 •

@bhatvikrant I will assume you guru in redux persist, if you solve this issue. Im stuck for 2 Months. Plz Help
stackoverflow.com/questions/695872...

Collapse
 
moataz0 profile image
Moataz0 •

Thanks a lot

Collapse
 
bhatvikrant profile image
Vikrant Bhat •

My pleasure!

Collapse
 
halltech profile image
Olajide Ayomide •

I'm dispatching a user details, and everything is been saved into local storage, is that not dangerous??