TanStackT
TanStack12mo ago
2 replies
urgent-maroon

Get index of pushed value in field array

Is there a way to get access to the index of a field that was pushed to a field array? It doesn't look like anything is returned from the pushValue() method. For context, I have an add/edit modal that renders an item in the modal that I am either adding or editing, and that is determined by the index in the array. This is fine with selecting an item to edit because the index was already defined, but when adding I would have to do something like setSelectedIndex(form.state.values.items?.length - 1) which feels like could lead to edge cases since there's no guarantee the item was pushed before setting that index, right?
Was this page helpful?