Replies: 1 comment 1 reply
-
Ah, I was just misunderstanding how react-hook-form works. The state is always based on the input values from the DOM. Adding this worked:
https://codesandbox.io/s/react-hook-form-usefieldarray-forked-1b8ff?file=/src/index.js |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
I have a form with an array of entries. When the form is submitted, a request is made for each entry and I'd like to update the form with the success status of each request. The
getValues
function returned byuseForm
is bound to the form state at the time of the render when it was created, so using it asynchronously can return stale data. Here is an example showing my use case (code included at bottom):https://codesandbox.io/s/react-hook-form-usefieldarray-forked-dcjv5?file=/src/index.js
I can get the desired behavior by sticking the form data in a ref that I update as each request completes, but then I'm managing the form state externally. Is there any way to get the current state of the form in an asynchronous fashion such as this?
Beta Was this translation helpful? Give feedback.
All reactions