what is the logic behind returning defaultFormState if form doesnt exist ? #202
-
HI, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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.
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 callback in a From here you might think you could solve this problem by not rendering form children until the form state is ready. Normally, that would probably work. But in our case, you can consume the form state from outside the ValidatedForm, so that doesn't fully solve the problem. Speculation time: Something that might be worth playing around with in the future is Suspense. It might theoretically be possible to suspend consumers until after the form state is initialized, but I don't think Suspense as a feature is ready for that yet. The new Also that approach might not work for users not using JS. It probably depends on what Remix ends up doing with Server components, and what other things React supports other than promises in the Again, this last part is just speculation. |
Beta Was this translation helpful? Give feedback.
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.
useEffect
runsuseEffect
runsSo 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 …