Schema related / getYupConstraint

getYupConstraint

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

1const constraint = getYupConstraint(schema);

#Parameters

schema

The yup schema to be introspected.

#Example

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