Zod with zustand #1722
Unanswered
karelnagel
asked this question in
Ideas
Replies: 2 comments
-
|
Hey 👋. Can I use this for a react native app alongside persist middleware? Was looking for something like this |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
i highly recommend to use a zod schema to verify the persisted values meet the expected runtime schema. Otherwise there can be a lot of impossible to reproduce bugs in your app (depending in the user's device state). To make this easy to use (so i actually do it) i have written following helper util, feel free to use that: https://gist.github.com/LeonMueller-OneAndOnly/3f8fe879b257716594bfa9d4562d3ece |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Would you be interested in adding a middleware that checks that the new state is a valid zod type? I just made a example for myself and thought that this might be useful for more people to avoid state corruption.
Example use case: shows error message if trying to create invalid state
Haven't tested this a lot, but let me know what you think.
Beta Was this translation helpful? Give feedback.
All reactions