I need final-form
to be able to add array of form field records. But want to display only one field of array at a time. Like on left side I will have customer id
or index
which user will select and on right side i have to show customer corresponding to that index
. I am able to add reac-final-form-array
, but it always show all array elements. What should be the right approach to show only selected customer.
Please check the below code for reference. Hope my question is clear, if not please let me know, will add more explanation.
<FieldArray name="customer">
{({ fields }) => (
fields.map((name, index) => (
<div key={index}>
<Field name={`${name}.firstName`} />
<Field name={`${name}.lastName`} />
</div>
))
)}
</FieldArray>
To add new customer:
<div className="buttons">
<button
type="button"
onClick={() => push('customers', undefined)}>
Add Customer
</button>
</div>
Currently its looking like:
Find the below code.
Check the codesandbox link here