Errors properties off by one render outside render
See original GitHub issueDescribe the bug
When we need to do something after the validation (in another function) is done, it seems like errors-properties are off by one render on their values.
To Reproduce Steps to reproduce the behavior:
- Open console (to see output)
- Go to firstName input-field
- Remove John
- Insert a single space-character ’ ’
- Click outside input-field (to trigger onBlur)
- Look at console-output
- Go to firstName input-field
- Remove the single space and leave input blank
- Click outside input-field (to trigger onBlur)
- Look at console-output
Codesandbox link (Required) https://codesandbox.io/s/small-thunder-nq0t4
Expected behavior
Expected that errors.firstName contains the error as the same as error does in the console.
Screenshots
(Image above) This one shows that errors contains the correct error, but errors.firstName is undefined. Should not say Do something. The UI-error is correct.
(Image above) This one shows that errors contains the correct error, but errors.firstName is errors previous value. Should say Don't do something. The UI-error is correct.
Additional context Have tried the same in JS (not TS) same result. Tested on version: 7.2.2 and 7.1.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:18 (10 by maintainers)

Top Related StackOverflow Question
Can’t reproduce the error on CodeSandbox, maybe there is something else conflicting in my project. So i confirm that all problems gone with this v7.2.4-beta.0
EDIT: For who has the same problem. The new version has spread {…register} with onChange prop, so if you need to define onChange conditionally, define before the {…register}.
Looked at that solution earlier, but got nasty when our forms are getting bigger.
https://codesandbox.io/s/throbbing-snow-ji72p
Seems like it works nicely! Tested in codesandbox.io and on my local project.
Had to change from
e.currentTarget.valuetoe.target.valueCause the currentTarget is null. Guess it has something to do with the async, but not any issue.