Skip to content

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) ​

NameTypeDescription
schemaA 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) ​

NameTypeDescription
schemaA 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 zod nor yup is a hard dependency of react-form-dto — both are declared as optional peer dependencies, so installing react-form-dto alone does not pull either in.
  • A resolver runs against the whole values object on every trigger() call; its errors are merged with any per-field validations already on the DTO (the resolver wins on conflicts).