Next.js Discord

Discord Forum

Managing persisted Zustand state in localStorage

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Hey all

I have a new app that I'd like to build with Zustand. One of the requirements is persisting some of it's state in localStorage (some user preferences etc). Even though we're using use client, I'm running into issues on page refresh where the localStorage isn't available on the server and subsequently, state is off. What would be the best way to solve this?

1 Reply

Short-tailed Albatross
hey
hoe did you handle clearing the state/ updating states on new pages,
in my case i am using zustand when the entityPage Pnloads and that might be tricky if there are many entities to be opened,
so was wondering how to clear upon change
any advice will be amazing, thank you