FormProvider
This component hosts the form context and allows consuming components to subscribe to the context and use createForm props and methods.
Props
| Name | Type | Description |
|---|---|---|
| form | UseFormReturn | FormProvider requires the complete form object returned by createForm. |
Avoid using nested FormProvider
import { createForm, FormProvider } from "solid-hook-form"
export const ExampleForm = () => {
const form = createForm({
defaultValues: {
nested: ""
}
})
const { handleSubmit } = form
const onSubmit = (values) => {
console.log(values)
}
return (
<FormProvider form={form}>
<form onSubmit={handleSubmit(onSubmit)}>
<NestedInput />
<button type="submit">Save</button>
</form>
</FormProvider>
)
}