Idea to explore: persist Zustand state to localStorage
1 February 2023 (Updated 1 February 2023)
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.
Tagged:
Random ideas
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment