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
useFieldArray generates an ID for each item of the array it manages. Those IDs are to be used as keys when rendering the React elements for each item.
At this time, this assignment of IDs remains private to the hook (it is managed by the ids ref).
Proposal
useFieldArray should return a way to access the contents of the ids ref.
Returning the ref itself would be dangerous for correctness reasons. Returning a getIds() function that returns a copy of the array may be preferable.
Use case
We need to track which items of an array have been added after the form has been initialized.
To achieve this, we've written a hook based on useFieldArray that wraps the mutation methods (append, etc.), so we can properly track the indexes of the new items. But this strategy is not as robust as using IDs: if something external came to update the contents of the array, it is not possible to perform a sound reconciliation of these changes with the indexes we've been tracking.
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
-
Context
useFieldArray
generates an ID for each item of the array it manages. Those IDs are to be used as keys when rendering the React elements for each item.At this time, this assignment of IDs remains private to the hook (it is managed by the
ids
ref).Proposal
useFieldArray
should return a way to access the contents of theids
ref.Returning the ref itself would be dangerous for correctness reasons. Returning a
getIds()
function that returns a copy of the array may be preferable.Use case
We need to track which items of an array have been added after the form has been initialized.
To achieve this, we've written a hook based on
useFieldArray
that wraps the mutation methods (append
, etc.), so we can properly track the indexes of the new items. But this strategy is not as robust as using IDs: if something external came to update the contents of the array, it is not possible to perform a sound reconciliation of these changes with the indexes we've been tracking.Would you be open to implement this feature ?
Beta Was this translation helpful? Give feedback.
All reactions