React Final Form: Field Array implementation guide State on Add/Remove Actions
I'm optimizing some code but Does anyone know how to I need some guidance on I'm using React Final Form to manage a dynamic form with an array of fields, but I'm running into an scenario where adding or removing fields doesn't seem to update the form state correctly. I'm trying to implement a form where users can add multiple email addresses dynamically. However, when I add an email field and then attempt to submit the form, the values are not getting registered properly. Hereβs a simplified version of my code: ```javascript import React from 'react'; import { Form, Field, FieldArray } from 'react-final-form'; const EmailForm = () => { const onSubmit = (values) => { console.log('Form Values:', values); }; return ( <Form onSubmit={onSubmit} render={({ handleSubmit }) => ( <form onSubmit={handleSubmit}> <FieldArray name="emails"> {({ fields }) => ( <div> {fields.map((name, index) => ( <div key={name}> <Field name={name} component="input" placeholder={`Email #${index + 1}`} /> <button type="button" onClick={() => fields.remove(index)}> Remove </button> </div> ))} <button type="button" onClick={() => fields.push()}>Add Email</button> </div> )} </FieldArray> <button type="submit">Submit</button> </form> )} /> ); }; export default EmailForm; ``` The scenario arises when I add or remove email fields. When I check the console output upon submission, it logs `{ emails: [] }` even though Iβve added one or more email fields. I've ensured that the `name` prop in the `Field` component matches the `name` in `FieldArray`. Iβve tried re-initializing the form state with `useEffect`, but that didn't resolve the scenario. Also, no warnings or errors are shown in the console, making it harder to debug. Am I missing something in the configuration, or is there a common pitfall I should be aware of with React Final Form's FieldArray? I'm using `react-final-form` version 6.13.1. I'm working on a web app that needs to handle this. I'm developing on Debian with Javascript. Could this be a known issue? I'm working with Javascript in a Docker container on Ubuntu 20.04. I'm on macOS using the latest version of Javascript. Any advice would be much appreciated.