Description
Are you submitting a bug report or a feature request?
bug report (reopening #142)
What is the current behavior?
I have a FieldArray for an outer array, and then a conditionally-visible FieldArray for an inner array. Pushing to the outer field always pushes to the initially-visible index, whereas pushing to the inner field works correctly. (The working case is not shown in the sandbox, but the third-level arrays do work)
When inspecting the field array values in the debugger it all looks correct, it is pointing at the correct item. My guess is that it's something to do with useConstant currying the mutators. Maybe that hook needs to reinitialize when the passed field name changes?
In my project I was originally passing in fields
that FieldArray gives to the render function down to the child component and using the push()
function available there, and that also did not work.
What is the expected behavior?
push()
should push the item into the correct array index.
Sandbox Link
https://codesandbox.io/s/elastic-kapitsa-qw0ku
Directions
- Click "Push with useFieldArray". New item is added to OuterValues[0].NestedValues.
- Click "Push with form mutator". New item is added to OuterValues[0].NestedValues.
- Change index from 0 to 1 using select at top of form.
- Click "Push with useFieldArray". New item incorrectly added to OuterValues[0].NestedValues.
- Click "Push with form mutator". New item correctly added to OuterValues[1].NestedValues.
What's your environment?
React 17, latest everything else.
Workaround for others
Don't use push()
exposed by FieldArray
's fields
for this use-case. Instead, use form.mutators.push
and pass in the full field name e.g. push('OuterValues[1].NestedValues', { ... })
.