field-form
field-form copied to clipboard
How use List with object values and mapped to fields form?
When using a list where each item contains two fields you cannot use the object keys corresponding to the form fields
Example of how I tried and failed
const initialValues = [
{ firstName: 'test', age: 100 },
{ firstName: 'test2', age: 110 },
];
...
<List name="users" initialValue={initialValues}>
{(fields, { add, remove }, { errors }) => {
return fields.map((field, index) => (
<>
<Field name="firstName" initialValue={initialValues[field.key].firstName}>
<input />
</Field>
<Field name="age">
<input />
</Field>
</>
));
}}
</List>
...
bump