Every once in a while in your react app or any front end app you stumble on having to save data in user’s browser and the best we have for that is localstorage.

But you don’t want to store your application data on her browser forever so you must set an expiration policy to it.

The very simple one which I did for my react typescript app is this one.

It saves data with an “expriy” key with it as 7 days from now. And while retrieving back the expiry is removed and we get back the original unmodified object. Helpful indeed!