I have some state with React recoil, but whenever the page is manually refreshed, the recoil state is reset.
Is this normal behaviour, because i know other state management libraries like flux
and react-redux
will do this.
Is it best practise to save it into localStorage
to actually have it persisted in the browser (because localStorage is also a synchronous api, so that could definitely also cause some issues.)
Even though it is a fairly new library, is there some way to persist state even on manual page refreshes?
I have some state with React recoil, but whenever the page is manually refreshed, the recoil state is reset.
Yes, it's normal behavior.
Is this normal behavior because I know other state management libraries like flux and react-redux will do this.
Yes, only a subset of the state management libraries persists the data themselves. It's more common to find external libraries that do that or custom solutions.
Is it best practice to save it into localStorage to actually have it persisted in the browser (because localStorage is also asynchronous API, so that could definitely also cause some issues.)
It depends on your needs:
indexedDB
sessionStorage
could be the right solutionLet's say that without knowing your use case it's hard to suggest something 😉
Even though it is a fairly new library, is there some way to persist state even on manual page refreshes?
Yes, with useRecoilTransactionObserver_UNSTABLE
you could get notified of every Recoil change and persisting the data. Then, with RecoilRoot' initializeState
you could restore it. As you said, the library is new and the APIs could change rapidly in the next months 😉