Bello Mayowa
Bello Mayowa

Reputation: 55

How to set expiration time for data stored in ReactJs localStorage

I need help on how to clear an Item or localStorage after a certain time even if the website is not currently working. More like a timeout when the localStorage should be cleared. Thank you

Upvotes: 5

Views: 12802

Answers (1)

João Cunha
João Cunha

Reputation: 10307

localStorage does not have support for expiration dates.

You can although save in localStorage a timestamp and next time the app starts up, check the timestamp and if it is too old than clean your app's localStorage.

Another way, if you want to set an expiration date on something, you can try with Cookies

There are some packages that help with this like js-cookie

Upvotes: 6

Related Questions