Preserve form state integrity via some invariance API #1220
Unanswered
vitormarkis
asked this question in
Ideas
Replies: 0 comments
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.
-
Problem
I have two dropdown in my form, categories and movies.
If I select a category, some movie, and then change the category, the movie value should reset to the first option of the new movie list. Otherwise, the form would keep a movie value that doesn't belong to the selected category.
Solution with current API
@crutchcorn suggested using field listeners to update the form state and enforce this integrity.
Why I don't like this solution:
Proposal
If I had to design such API, I would something like Saphyra does with reducer:
Or simply:
Basically a pure function that transforms the state before it is ready to notify observers/listeners, enforcing the form values to always be in a valid state.
Keypoints:
Up to discussion
How often should this function run? Can it support async await? Should it run before or after the validation?
Further discussion:
https://discord.com/channels/719702312431386674/1346611817098641438
Beta Was this translation helpful? Give feedback.
All reactions