createZodForm
Creates a form for a Zod schema
import { createZodForm } from '@jcoreio/zod-forms'
createZodForm<T extends z.ZodTypeAny>(options: { schema: T }): ZodForm<T>
Requirements
If you want to use .transform
s in schema
, you must declare them via
zod-invertible
so that it's possible
to format final values into raw values; otherwise createZodForm
will throw an error.
Returns ZodForm<T>
An object with the following properties:
root
- the rootFieldPath
get
- shortcut forroot
.get(...)
FormProvider
- React component to provide form context to its descendantsuseFormContext
bound to schema typeT
useFormStatus
bound to schema typeT
useFormValues
bound to schema typeT
useInitialize
bound to schema typeT
useSubmit
bound to schema typeT
useArrayField
bound to schema typeT
useField
bound to schema typeT
useHtmlField
bound to schema typeT
FormProvider
A React component to provide form context to its descendants.
const { FormProvider } = createZodForm({ schema })
Example
function MyForm() {
return (
<FormProvider>
<MyFormContent />
</FormProvider>
)
}