⚡️ createFormControl
- Allow us to start subscribing outside of the react component
const { formControl, control } = createFormControl(props)
function App() {
const { register } = useForm({
formControl,
})
return <form />
}
function Test() {
useFormState({
control // no longer need context api
})
}
⚡️ subscribe
- subscribe form state update without re-render
- subscribe outside of the react component
const { formControl } = createFormControl(props)
control.subscribe({
formState: { isDirty: true },
callback: (formState) => {
if (formState.isDirty) {
// do something here
}
}
})
function App() {
const { register } = useForm({
formControl,
})
return <form />
}