Valibot Schema / getValibotConstraint

getValibotConstraint

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

1const constraint = getValibotConstraint(schema);

#Parameters

schema

The valibot schema to be introspected.

#Example

1import { getValibotConstraint } from '@conform-to/valibot';
2import { useForm } from '@conform-to/react';
3import { object, pipe, string, minLength, optional } from 'valibot';
4
5const schema = object({
6  title: pipe(string(), minLength(5), maxLength(20)),
7  description: optional(pipe(string(), minLength(100), maxLength(1000))),
8});
9
10function Example() {
11  const [form, fields] = useForm({
12    constraint: getValibotConstraint(schema),
13  });
14
15  // ...
16}