Reputation: 254
How do I maintain the state of store in redux?
On logging in, the details of the user are stored in the store as {user:Object}
. But on refreshing the page the state is lost and becomes equal to the initial value.
How do I handle this?
Is it necessary to store state in localStorage? Is there an alternative?
Upvotes: 2
Views: 276
Reputation: 3198
If you refresh the page it's expected that the state of the app start fresh again from the initial states.
If you need to store the user credentials just to avoid logging in, it means something is wrong. For instance you should be using sessions and perphaps have the sever side return the initial state, with the user info in it, rather than storing the user info on the client side, which is insecure.
However if you need to persist more state on refresh, you can have a look at something like this
Upvotes: 2