Reputation: 341
I have react component in which I need to persist data when the I refresh page. What should the solution for it? Please help
Upvotes: 4
Views: 7632
Reputation: 2646
You can use sessionStorage or localStorage for it. Store whatever data you want to persist in storage. When you refresh the page get that data from storage in your constructor or componentWillMount (UNSAFE).
Take a look at this article for info https://medium.com/bother7-blog/localstorage-and-you-2660342a60cb
Upvotes: 4
Reputation: 86
You could also use the npm package redux-persist or react-persist https://www.npmjs.com/package/redux-persist
Upvotes: 3