Validate a FormData submission
A browser form submits fields as FormData and needs Yup validation before processing.
Conform · Function
parseWithYup validates submitted FormData or URLSearchParams against a Yup schema and returns a Conform submission overview. It supports synchronous validation by default and asynchronous Yup validation when configured.
parseWithYup accepts submitted FormData or URLSearchParams and validates it against a Yup schema. It returns Conform’s submission overview, using synchronous validation by default or Yup’s asynchronous validate method when async is enabled.
parseWithYup(payload, options)| Name | Type | Description |
|---|---|---|
payload | FormData | URLSearchParams | FormData or URLSearchParams containing the submitted form values. |
options | object | Configuration containing the Yup schema and optional asynchronous-validation setting. |
options.schema | Schema | (() => Schema) | A Yup schema, or a function returning a Yup schema. |
options.async | boolean | When true, uses Yup validate instead of validateSync. |
A Conform submission overview produced by validating the payload with the provided Yup schema.
import { parseWithYup } from '@conform-to/yup';
import * as yup from 'yup';
const schema = yup.object({
email: yup.string().email().required(),
password: yup.string().required(),
});
const formData = new FormData();
formData.set('email', 'user@example.com');
formData.set('password', 'secret');
const submission = parseWithYup(formData, { schema });
console.log(submission.status);Creates a Yup schema, parses submitted FormData, and reads the resulting submission status.
A browser form submits fields as FormData and needs Yup validation before processing.
A URL-encoded form submission must be checked against a Yup schema.
Validation includes asynchronous Yup checks such as remote or deferred rules.
A form’s schema must be generated dynamically for the validation call.
parseWithYup parses FormData or URLSearchParams with a supplied Yup schema and returns a submission overview. The schema option can be either a Yup schema or a function that returns one.
Follow-up: When would you pass a schema function? Use one when schema construction needs to be deferred or computed at validation time.
By default, parsing uses Yup's synchronous validateSync behavior. Set async to true to use Yup's validate method instead.
Follow-up: What is the practical consequence? The validation flow must handle the asynchronous result rather than assuming synchronous completion.
The payload may be a FormData object or a URLSearchParams object, depending on how the form was submitted. The helper then applies the configured Yup schema to that payload.
Follow-up: How would you support a form submitted through a standard multipart request? Pass its FormData payload to parseWithYup and configure the Yup schema for the fields.
@conform-to/yupgetYupConstraintuseFormFormDataURLSearchParams