-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: useWatch not triggered after form reset() to empty object #10238
Comments
I can confirm that this is happening. The reason useWatch is clearing in the second time because, The reset function resets the form values to the default values if no value or empty object is passed as first argument. In this case, on click of "reset to values" your default value is updated to the object you have provided that is Regarding the issue where useWatch and watch are returning different results because in the reset function useWatch is updated using this value,
while the watch method is updated using
Both gives different results when object is empty, in the first case _defaultValues is used and in the second cloneUpdatedValues is used. @bluebill1049 if you think this behaviour should be modified, I request you to assign this issue to me, and I'll be able to submit a PR fixing this issue. |
thanks @devakrishna33 for looking into this 🙏 let me know if you need any help. |
…atch when reset is called with empty object
… is called with empty object (#10244)
Thanks for looking into this and for the great explanation @devakrishna33. Appreciate the help. I can confirm that using |
Version Number
7.43.9
Codesandbox/Expo snack
https://stackblitz.com/edit/react-ts-zogyhj?file=App.tsx,style.css,UseWatchComponent.tsx,WatchComponent.tsx,ValuesComponent.tsx
Steps to reproduce
Expected behaviour
I would expect useWatch to be triggered with the updated values that are used with the form.reset method the first time it is set to an empty object, in the same way that it is triggered when the form is set to an object with values.
What browsers are you seeing the problem on?
Chrome, Edge
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: