Muhammad Bilal
Muhammad Bilal

Reputation: 341

How to persist data in react on page refresh

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

Answers (2)

Shubham Gupta
Shubham Gupta

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

Xia Amendolara
Xia Amendolara

Reputation: 86

You could also use the npm package redux-persist or react-persist https://www.npmjs.com/package/redux-persist

Upvotes: 3

Related Questions