Skip to content

what is the logic behind returning defaultFormState if form doesnt exist ? #202

Answered by airjp73
tomer-yechiel asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

Since the form state doesn't get created until the ValidatedForm component mounts, all consumers of that form state will necessarily mount before the form state is ready. Example: if you have an input that's a child of the form component this will happen.

  • ValidatedForm renders for the first time
  • Input renders for the first time
  • Input useEffect runs
  • ValidatedForm useEffect runs
    • Now the form store is initialized
  • Input will rerender & relevant effects will rerun with the initialized form state

So if the Input threw an error before the form state was ready, that would fundamentally not work because your form would error every time.

Also important to note that, if you're using a form …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tomer-yechiel
Comment options

Answer selected by tomer-yechiel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants