I trying to create 2 FieldArray containers with arrayHelpers. Each of them working with different object. Obj1 and Obj2 have their arrayHelper and each of them know how to add and remove objects to/from array.
I want to do some kind of toolbar with two buttons "Add Obj1" and "Add Obj2" outside of these two containers. The question is how can I work with arrayHelper outside of these containers? Or could you suggest another flow how can change my array? The problem is if I change my array from parent - I can't work with props.values only with props.obj1 but in this case my changes are not saving.
<FieldArray name="obj1"
render={arrayHelpers => {}/>
<FieldArray name="obj2"
render={arrayHelpers => {}/>
<div class="toolbar">...buttons</div>
To access arrayHelpers outside of a FieldArray, you can use refs.
I've created a code sandbox, showing how you can do this:
https://codesandbox.io/s/using-refs-to-access-child-methods-cps7w
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With