Replies: 1 comment
-
Watch API re-render at the root |
Beta Was this translation helpful? Give feedback.
0 replies
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.45.2
Codesandbox/Expo snack
https://codesandbox.io/s/react-hook-form-usefieldarray-template-forked-7vk2rg?file=/src/index.js
Steps to reproduce
Expected behaviour
Reading the docs useWatch and watch should work on the same way with the exception that useWatch could have a better performance when it is used in isolated components, avoiding re-renders on higher scope components.
The expected behavior is that both methods should return different javascript refs to array objects not only when new items are add or removed from the array itself, but also each time an item is updated by its onChange controlled handler.
In the linked code you can see that if we modify some of the items "value" prop, the useMemo which computes the result and has the array field ref in its dependency array will be re-evaluated only if we used useWatch().
Otherwise, if watch() was used for watching the array, the results depending on it will only be re-evaluated if we add / remove or modify the array directly.
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions