watch vs. useWatch array length inconsistency when using useFieldArray
See original GitHub issueDescribe the bug
Not sure if this is a bug/can be improved but… when using useFieldArray
to insert/remove item to the fields, the resulting output (array) of that useWatch
doesn’t have a consistent length with the array length of updated fields after the insertion/removal.
To Reproduce Steps to reproduce the behavior:
- Go to the CSB link, clear the console after render.
- Click on “insert” or “remove”.
- See the console. Check the length of the
fields
vs. the length of theuseWatchedItems
on the first render loop.
Codesandbox link (Required) https://codesandbox.io/s/watch-vs-usewatch-field-array-length-inconsistency-bi8it?file=/src/App.jsx:1365-1650
Expected behavior
The length of the fields
and the length of the useWatchedItems
should be the same on each render cycle.
Additional context
When watch
is used instead of useWatch
though, the watched array length seems to be consistent with the fields
array length on each render. 👍
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
useFieldArray - Simple React forms validation
Custom hook for working with Field Arrays (dynamic form). The motivation is to ... You can watch this short video to visualize the...
Read more >react-hook-form - Awesome JS
fix(useWatch): default value for array of inputs (#9555) fix Controller example using ... fix #9134 useFieldArray validation action inconsistency (#9136)
Read more >How to make a dynamic watch()/usewatch() with react-hook ...
length === 0 || watchThese.fullName}/> which works but is obviously triggered by every field. How could I generate a dynamic watch()/useWatch() ...
Read more >react-hook-form: Versions - Openbase
fix #9134 useFieldArray validation action inconsistency (#9136) close #9126 ... useController by integrating with useWatch ✌ package size-reduction ...
Read more >React Hook Form - useFieldArray - YouTube
In this session, we are taking a look at the useFieldArray custom hook to manage your dynamic form fields.working example: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, the last re-render will bring the updated field values.
Previously its a bug because it didn’t return the correct wath value, i will do some investigation with inconsistent watch value. I know the root cause, because useWatch need to trigger another setState to update the value, but worth to do some investigation, if not working then will close this issue.