New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue: Async Default Values Not Loaded When Promise Resolves Immediately/Quickly #10195
Comments
Would you like to send us a PR on this issue? |
I faced with the same problem today |
if Maybe replace of react-hook-form/src/useForm.ts Lines 84 to 100 in 8c76ad3
|
…ct-hook-form#10203) * 🍄 close react-hook-form#10195 close async defaultValues not load * save some bytes * fix api contract * pin pnpm to v7
Version Number
7.43.8
Codesandbox/Expo snack
https://codesandbox.io/s/useformstate-forked-21tel9?file=/src/App.js
Steps to reproduce
The error described in the issue title is apparent as soon as Code Sandbox loads. Upon loading the sandbox, it is apparent that the input field does not have the expected default value, and the value will never load automatically.
If
setTimeout
's timeout value is increased from0
to500
(or any other value higher than0
), then the form behaves as described in the "Expected Behavior" section.This is an issue when using libraries that cache responses and thus immediately resolve the promises they return.
Note that, if one clicks the
toggle
button on the page twice (unmount and remount occurs), then "mark" shows up on the field.The problem is with this code snippet, which is found within
creatFormControl.js
:createFormControl
is invoked from within theuseForm
hook; however,createFormControl
is invoked from the main body ofuseForm
instead of being invoked from within an effect (useEffect
). SincecreateFormControl
causes side effects, it should be invoked from within an effect.After cloning this repository, commenting out the above code snippet within
createFormControl
and recreating that snippet withinuseEffect
inside the body ofuseForm
, the issue was resolved.Expected behaviour
Value "mark" should be present in input field without any manual action after form fully loads.
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: