You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior
Having an onFocus callback should not cause the input to reregister on validation failure
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: OSX High Sierra
Browser: Chrome
Version: 81.0.4044.113
Additional context
The reregistering problem will also occur if you focus the Controller in react dev tools. If you have multiple Controllers in the form with onFocus callbacks then they will all exhibit the same behaviour
The text was updated successfully, but these errors were encountered:
The reason for this is because your forgot to memoize your function.
In Line 107 of Controller, notice that the onFocus is part of useCallback's dependencies of registerField hence re-register happen because onFocus handler is creating new reference for every render.
Describe the bug
When using a component with an onFocus callback it reregisters itself after validation failure (or if focused in react dev tools)
To Reproduce
Steps to reproduce the behavior:
Codesandbox link (Required)
https://codesandbox.io/s/controller-issue-6gr5t?file=/src/index.js
Expected behavior
Having an onFocus callback should not cause the input to reregister on validation failure
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
The reregistering problem will also occur if you focus the Controller in react dev tools. If you have multiple Controllers in the form with onFocus callbacks then they will all exhibit the same behaviour
The text was updated successfully, but these errors were encountered: