I'm new to react and i'm stuck in a situation. The application i'm currently working on has multiple sections say section 1 ,section 2, ... Each of these section have form which has different fields. I'm in need to doing the validation of form present in parent component in the child component.
function App() {
return <>
//section 1 code here
<section 2/>
<section 3/>
<section 4/>
</>
}
is there a way i can pass the form data of section 1 to section 2 and validate the data upon a button click in section 2. form data of section 2 to section 3 and validate the data upon a button click in section 3. ... for other sections
i'm using the react hook form and usefieldarray for add and remove fields (dynamically)
You should be able to achieve this by managing the form data and validation at the parent component level and passing down the necessary data and functions to the child components. Since you are using React Hook Form, you can use the useForm hook to manage the form state and validation.
Something like this should work,