Replies: 2 comments 2 replies
-
thanks for the detailed issue report, form state is always re-rendered in the next render with |
Beta Was this translation helpful? Give feedback.
1 reply
-
I believe, that you can do that this way: const x = register('address.postalCode')
return (
<input {...x} onChange={async (e) => {
// Validation is async and onChange returns promise
// https://github.com/react-hook-form/react-hook-form/blob/master/src/logic/createFormControl.ts#L735
await x.onChange(e)
// Call your custom onChange handler
onChange()
}}/>
)} |
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.
-
Version Number
7.33.1
Codesandbox/Expo snack
https://codesandbox.io/s/gracious-herschel-5lt2ll?file=/src/App.js
Steps to reproduce
Trying to fill in some form fields based on a input of another form field when this is valid. Fairly new to react hook forms, so perhaps I'm looking at this all wrong. Issue I'm facing is that the onchange is triggered sooner than the validation and the value look to be one step behind
When the onChange is triggered, the errors is empty is some cases where it shouldn't be and it continues with invalid data.
How can I make sure the validation is done before the onChange event.
In the codesandbox, when you begin to type. the initial console is 1 and errors is undefined (which is incorrect) and going on to 12345 and then back to 1. When it's 1234 the error should be undefined, it's only undefined in the next onchange
Expected behaviour
We the getAddress is called, the errors should reflect the value of the input
What browsers are you seeing the problem on?
Chrome
Relevant log output
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions