Skip to content

createFormControl

Create form state and ready to be subscribed

This function create the entire form state subscription and allow you to subscribe update with or without react component.

Props


This following table applied to FormProvider, useFormContext accepts no argument.

NameTypeDescription
...propsObjectUseFormProps

Examples:


const { formControl, control } = createFormControl({
mode: 'onChange',
defaultValues: {
firstName: 'Bill'
}
}})
function App() {
const { register } = useForm({
formControl,
})
return (
<form>
<FormState />
<Controller />
</form>
);
}
function FormState() {
useFormState({
control // no longer need context api
})
}
function Controller() {
useFormState({
control // no longer need context api
})
}
const { formControl } = createFormControl(props)
formControl.subscribe({
formState: { isDirty: true },
callback: (formState) => {
if (formState.isDirty) {
// do something here
}
}
})
function App() {
const { register } = useForm({
formControl,
})
return <form />
}

Thank you for your support

If you find React Hook Form to be useful in your project, please consider to star and support it.