gamer
gamer

Reputation: 5863

react redux state changed to initial after browser refresh

I am making a react app using redux. I am going great except one issue.

Whenever I refresh the browser my state changed to initial state. Lets say I have a user authenticated and I have set him as authenticated: true and after authenticating when I refresh the page the state changed to initial and authenticated:false is set.

I am confused why is this happening ?

Can anyone point what might be the issue here

Upvotes: 1

Views: 5378

Answers (1)

Cool Acid
Cool Acid

Reputation: 153

Redux stores are not persistent. When the page reloads, all data is initialized again. If you would like to save a piece of your store (or the whole thing) you will need to save it in localstorage, or saving it to your server and making a REST request asking for the data again.
You can use this package to save your store into localstorage.

Upvotes: 7

Related Questions