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 .transforms in schema, you must declare them via
zod-invertible so that it's possible
to invert parsed values back into input values; otherwise createZodForm will throw an error.
Returns ZodForm<T>
An object with the following properties:
root- the rootFieldPathget- shortcut forroot.get(...)FormProvider- React component to provide form context to its descendantsuseFormContextbound to schema typeTuseFormStatusbound to schema typeTuseFormValuesbound to schema typeTuseInitializebound to schema typeTuseSubmitbound to schema typeTuseArrayFieldbound to schema typeTuseFieldbound to schema typeTuseHtmlFieldbound 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>
)
}