Schema related / 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 { getZodConstraint } from '@conform-to/zod';
2import { useForm } from '@conform-to/react';
3import { z } from 'zod';
4
5const schema = z.object({
6  title: z.string().min(5).max(20),
7  description: z.string().min(100).max(1000).optional(),
8});
9
10function Example() {
11  const [form, fields] = useForm({
12    constraint: getZodConstraint(schema),
13  });
14
15  // ...
16}