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 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.
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', { ... }).
The text was updated successfully, but these errors were encountered:
Similar problem, same fix. Working with nested arrays where the inner array is conditional or may be a different shape than its parent seems to cause some of the mutator functions passed through FieldArrayRenderProps to act up. However calling the form's mutator functions directly seems to work fine. Note that the name prop from FieldArrayRenderProps is correct for the field it should be rendering.
@erikras I think this bug is critical for work with useFieldArray and because of this reason useFieldArray could be deprecated in our project. Do you have any plans to fix it?
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 thepush()
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
What's your environment?
React 17, latest everything else.
Workaround for others
Don't use
push()
exposed byFieldArray
'sfields
for this use-case. Instead, useform.mutators.push
and pass in the full field name e.g.push('OuterValues[1].NestedValues', { ... })
.The text was updated successfully, but these errors were encountered: