issue: Watched arrays of objects does not update their reference after object field update [useFieldArray] #10929
-
Version Number7.46.1 Codesandbox/Expo snackhttps://codesandbox.io/s/ecstatic-merkle-cdqjgg?file=/src/App.tsx Steps to reproduce
Expected behaviourMemoized values built upon watched arrays should update when a field of an object in the array changes. The last version of react-hook-form where this works correctly is 7.13.0. If I downgrade the package to this version the list updates correctly. What browsers are you seeing the problem on?Firefox, Chrome, Safari Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is the expected behavior for https://react-hook-form.com/docs/useform/watch ![]() Field array data will be the same reference array inside form state to avoid re-rendering therefore using Just remove the use of Working demo: https://codesandbox.io/s/epic-swanson-gtqhsx?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
@DanielMarkiel
This is the expected behavior for
watch()
method on field array of react-hook-form latest version and it has been documented in here:https://react-hook-form.com/docs/useform/watch
Field array data will be the same reference array inside form state to avoid re-rendering therefore using
useMemo
oruseEffect
with change deps will not work.Just remove the use of
useMemo
to achieve your expected behavior.Working demo: https://codesandbox.io/s/epic-swanson-gtqhsx?file=/src/App.tsx