ContextForm

FormContext

FormContext provides a way to share a form state to another components in the tree.

const form = useForm(...)
<ContextForm.Provider value={form}>
{/* ....another components */}
</ContextForm.Provider>

useFormContext

useFormContext is a custom hook, this hook provides the same useForm hook API. If using typescript should pass type of the values.

This hook only will work if there is a parent with FormContext.

More details about React context https://reactjs.org/docs/context.html.

const {register, ...form} = useFormContext(...)
<Input placeholder="Name" {register('otherPerson.name')}/>