Resolvers
Adapters that plug a schema validation library into useForm/useFormDTO. See the Schema Validation guide for a full walkthrough.
Import
ts
import { zodResolver, yupResolver } from 'react-form-dto';
import type { Resolver, ResolverResult } from 'react-form-dto';Resolver<T>
ts
type ResolverResult<T> = {
values: T;
errors: Record<string, string>;
};
type Resolver<T extends object = any> = (
values: T
) => ResolverResult<T> | Promise<ResolverResult<T>>;Any function matching this shape can be passed as options.resolver to useForm/useFormDTO. zodResolver/yupResolver are adapters that produce one from a schema.
zodResolver(schema)
| Name | Type | Description |
|---|---|---|
schema | A Zod schema (anything with safeParse/safeParseAsync) | The schema to validate form values against. |
Maps each failing Zod issue's path (joined with .) to its message. zod is an optional peer dependency — install it yourself to use this.
yupResolver(schema)
| Name | Type | Description |
|---|---|---|
schema | A Yup schema (anything with .validate()) | The schema to validate form values against. |
Runs schema.validate(values, { abortEarly: false }) and maps each ValidationError's path to its message. yup is an optional peer dependency — install it yourself to use this.
Notes
- Neither
zodnoryupis a hard dependency ofreact-form-dto— both are declared as optional peer dependencies, so installingreact-form-dtoalone does not pull either in. - A resolver runs against the whole values object on every
trigger()call; its errors are merged with any per-fieldvalidationsalready on the DTO (the resolver wins on conflicts).