Here’s an idea. Persist Zustand state to localStorage using its persist middleware. To handle outdated localStorage state, you can:
- Clear the localStorage when the user logs out/is logged out automatically by your app.
- Persist Zustand in localStorage using a key that identifies your latest release. Perhaps some sort of Git commit hash. Then, when your app tries to hydrate Zustand state from localStorage, check if the commit hash that the localStorage item is stored under matches your latest release. If it does, all good. Otherwise, don’t hydrate and clear that item from localStorage.