简体   繁体   中英

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

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

您还可以使用npm软件包redux-persist或react-persist https://www.npmjs.com/package/redux-persist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM