You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there was any counter indications of using a custom key prop when rendering a fieldArray instead of the field.id automatically generated by the useFieldArray hook.
Indeed, using the latter leads to remount every time I call setValue on the main form (as intended in the docs). This is not a behaviour that I wanted, so I tried to set the key prop of each of my elements of my field array to a unique ID that is already present in my data I want to initialize the new appended field array with. In my case, this avoids regenerating the id and thus re-mounting my component because the key changed.
This seemed to work, but I'm not sure if I'm doing things as intended here and if it won't have any side effect breaking my whole app. I wanted to know if you have any ideas about this ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone,
I was wondering if there was any counter indications of using a custom
key
prop when rendering afieldArray
instead of thefield.id
automatically generated by theuseFieldArray
hook.Indeed, using the latter leads to remount every time I call
setValue
on the main form (as intended in the docs). This is not a behaviour that I wanted, so I tried to set thekey
prop of each of my elements of my field array to a unique ID that is already present in my data I want to initialize the new appended field array with. In my case, this avoids regenerating the id and thus re-mounting my component because the key changed.This seemed to work, but I'm not sure if I'm doing things as intended here and if it won't have any side effect breaking my whole app. I wanted to know if you have any ideas about this ?
Thanks a lot for your answer,
Beta Was this translation helpful? Give feedback.
All reactions