Skip to main content

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 format final values into raw values; otherwise createZodForm will throw an error.

Returns ZodForm<T>

An object with the following properties:

FormProvider

A React component to provide form context to its descendants.

const { FormProvider } = createZodForm({ schema })

Example

function MyForm() {
return (
<FormProvider>
<MyFormContent />
</FormProvider>
)
}