issue: useFieldArray gets reinitialised and IDs get reassigned on any change to the "values" prop #11141
Unanswered
rishitells
asked this question in
Q&A
Replies: 1 comment 5 replies
-
you shouldn't relay on those id, they are made for rendering array fields. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version Number
7.47.0
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/wizardly-bird-y9f9pq?file=%2Fapp%2Froutes%2F_index.tsx%3A20%2C2
Steps to reproduce
I have a form with mix of single fields and list (array) fields, and I am trying to update the form values with the fresh server data after a submission, by passing the
values
prop touseForm()
. However, I see that even if the array field values are unchanged from server data (only the single field value is changed), the array fields also get reinitialised and the IDs get changed, which causes the fields inside the array to lose all local state. This does not happen if allvalues
are unchanged.useForm
and include two fields -useFieldArray()
whose value never changes.values
.useFieldArray
assigns new IDs to the list fields.I see that
react-hook-form
just resets the whole form if current values are not deeply equal to previous values -But is there a reason for this hard reset even when there is only one changed field out of, say 10 fields?
Expected behaviour
When submitting the form and updating the
useForm
values with fresh server data where array field values remain the same,useFieldArray
should not reinitialize the list items. The IDs for list items should remain consistent if their corresponding data has not changed, preserving their internal state.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