#persist data across reloads | R3F
11 messages · Page 1 of 1 (latest)
Sounds like a job for useState
Nope
State loses when page reloads
It's either cookies, sessionStorage or localStorage
Yeah, I didn't catch that you really want it to persist on refresh/reload. I suppose sessionStorage or localStorage, depending on how you want the expiration to work.
If you happen to be using React, there are any number of hooks and state libraries for doing this in React-friendly ways.
if not, yeah, localStorage or sessionStorage, see https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage for the difference.
Could you please give me some examples??
Which hooks and libs could be useful in this situation
I think Zustand would be one of the simpler ways to do this in React:
https://github.com/pmndrs/zustand?tab=readme-ov-file#persist-middleware