Schema related / parseWithYup

parseWithYup

A helper that returns an overview of the submission by parsing the form data with the provided yup schema.

1const submission = parseWithYup(payload, options);

#Parameters

payload

It could be either the FormData or URLSearchParams object depending on how the form is submitted.

options

schema

Either a yup schema or a function that returns a yup schema.

async

Set it to true if you want to parse the form data with validate method from the yup schema instead of validateSync.

#Example

1import { parseWithYup } from '@conform-to/zod';
2import { useForm } from '@conform-to/react';
3import * as yup from 'zod';
4
5const schema = yup.object({
6  email: yup.string().email(),
7  password: yup.string(),
8});
9
10function Example() {
11  const [form, fields] = useForm({
12    onValidate({ formData }) {
13      return parseWithYup(formData, { schema });
14    },
15  });
16
17  // ...
18}