-
-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Validating atoms #1198
Comments
Thanks for opening this up. In terms of
I'm not sure about For forms, we have an experimental project jotai-form, FYI. |
Thanks @dai-shi 👍I'll try out the custom storage solution, as well as adding react-query validation. As to jotai-form, I was hoping its atomWithValidate could be adjusted here to accept either initialValue OR another atom, similar to how focusAtom or atom.ts does it |
jotaijs/jotai-form#4 is a new function related it. I don't think deriving atoms is very easy, and it may overlap with other native functions. Though, I' might be missing something. Would be great if you open a new issue there with some use cases. |
I think what's remaining in this issue is documentation for |
Closing this as it's a bit stale now. |
@dai-shi - this seems very necessary, there's no way to drop old values when changing data structure. This is storage agnostic. Should be something like:
|
Yeah, that's convincing. But, I'm not convinced to add an option. Let's add a util, which is less comfortable, but more flexible. |
Thanks for your superb work on this package! I'm enjoying using it.
Where an atom reads from an API (local storage, react query response, form input) rather than an in-memory value, we can't guarantee the value matches the expected type.
An example of this can be seen here: https://d5kn6.csb.app/#count=%22stored+value+may+not+match+your+expected+type%2C+if+it+has+been+written+by+previously+deployed+code%22
(Pressing the
+1
button on the above example shows how the business logic will fail with an invalid input type)The current implementation of atomWithValidate is written to apply validation on write, with a synchronous initialValue; but could we instead have validation nested into atoms (eg atomWithValidate's initialValue is an atom, therefore requiring
onMount
to provide a getter as well as a setter), and in this way perhaps compose the validation atom so that API responses could be validated during load?The text was updated successfully, but these errors were encountered: