Zod Schema / getZodConstraint

getZodConstraint

A helper that returns an object containing the validation attributes for each field by introspecting the zod schema.

1const constraint = getZodConstraint(schema);

#Parameters

schema

The zod schema to be introspected.

#Example

1import { useForm } from '@conform-to/react';
2import { getZodConstraint } from '@conform-to/zod';
3// If you are using Zod v4, update the imports:
4// import { getZodConstraint } from '@conform-to/zod/v4';
5import { z } from 'zod';
6
7const schema = z.object({
8  title: z.string().min(5).max(20),
9  description: z.string().min(100).max(1000).optional(),
10});
11
12function Example() {
13  const [form, fields] = useForm({
14    constraint: getZodConstraint(schema),
15  });
16
17  // ...
18}