Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts, Vi
Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts, Vi
Performant, flexible and extensible forms with easy to use validation.
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others. The goal is to make sure you can seamlessly integrate whichever validation library you prefer. If you're not using a library, you can always write your own logic to validate your forms.
Install your preferred validation library alongside @hookform/resolvers.
npm install @hookform/resolvers # npm
yarn add @hookform/resolvers # yarn
pnpm install @hookform/resolvers # pnpm
bun install @hookform/resolvers # bun| resolver | Infer values from schema |
criteriaMode |
|---|---|---|
| AJV | ❌ | firstError | all |
| ata-validator | ❌ | firstError | all |
| Arktype | ✅ | firstError |
| class-validator | ✅ | firstError | all |
| computed-types | ✅ | firstError |
| Effect | ✅ | firstError | all |
| fluentvalidation-ts | ❌ | firstError |
| io-ts | ✅ | firstError |
| joi | ❌ | firstError | all |
| Nope | ❌ | firstError |
| Standard Schema | ✅ | firstError | all |
| Superstruct | ✅ | firstError |
| typanion | ✅ | firstError |
| typebox | ✅ | firstError | all |
| typeschema | ❌ | firstError | all |
| valibot | ✅ | firstError | all |
| vest | ❌ | firstError | all |
| vine | ✅ | firstError | all |
| yup | ✅ | firstError | all |
| zod | ✅ | firstError | all |
Most of the resolvers can infer the output type from the schema. See comparison table for more details.
useForm<Input, Context, Output>()Example:
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod'; // or 'zod/v4'
const schema = z.object({
id: z.number(),
});
// Automatically infers the output type from the schema
useForm({
resolver: zodResolver(schema),
});
// Force the output type
useForm<z.input<typeof schema>, any, z.output<typeof schema>>({
resolver: zodResolver(schema),
});type Options = {
mode: 'async' | 'sync',
raw?: boolean
}
resolver(schema: object, schemaOptions?: object, resolverOptions: Options)| type | Required | Description | |
|---|---|---|---|
| schema | object |
✓ | validation schema |
| schemaOptions | object |
validation library schema options | |
| resolverOptions | object |
resolver options, async is the default mode |
Dead simple Object schema validation.
⚠️ Pass context via
useForm({ context }), not viayupResolver'sschemaOptions.schemaOptions.contextis overridden by the form context, so use theuseFormcontext object instead.
// Correct
useForm({
resolver: yupResolver(schema),
context: { foo: true },
});
// Avoid - schemaOptions.context will be ignored/overridden
yupResolver(schema, { context: { foo: true } });import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
const schema = yup
.object()
.shape({
name: yup.string().required(),
age: yup.number().required(),
})
.required();
const App = () => {
const { register, handleSubmit } = useForm({
resolver: yupResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};TypeScript-first schema validation with static type inference
⚠️ Example below uses the
valueAsNumber, which requiresreact-hook-formv6.12.0 (released Nov 28, 2020) or later.
…⚠️ If your schema uses
.default(...)on a field, that field becomes optional on the schema's input type (z.input) but stays required on its output type (z.output/z.infer) — the default only fills it in after validation. Passing a single generic touseForm<T>pins both to the same type and will conflict withzodResolver, which infers input and output separately. Either omit the generic and let it infer fromresolver, or specify all three explicitly:const schema = z.object({ debug_mode: z.boolean().default(true) }); useForm<z.input<typeof schema>, unknown, z.output<typeof schema>>({ resolver: zodResolver(schema), });
A simple and composable way to validate data in JavaScript (or TypeScript).
import { useForm } from 'react-hook-form';
import { superstructResolver } from '@hookform/resolvers/superstruct';
import { object, string, number } from 'superstruct';
const schema = object({
name: string(),
age: number(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: superstructResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age', { valueAsNumber: true })} />
<input type="submit" />
</form>
);
};The most powerful data validation library for JS.
import { useForm } from 'react-hook-form';
import { joiResolver } from '@hookform/resolvers/joi';
import Joi from 'joi';
const schema = Joi.object({
name: Joi.string().required(),
age: Joi.number().required(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: joiResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};Vest Declarative Validation Testing.
…Decorator-based property validation for classes.
⚠️ Remember to add these options to your
tsconfig.json!
"strictPropertyInitialization": false,
"experimentalDecorators": true…Validate your data with powerful decoders.
…A small, simple, and fast JS validator
import { useForm } from 'react-hook-form';
import { nopeResolver } from '@hookform/resolvers/nope';
import Nope from 'nope-validator';
const schema = Nope.object().shape({
name: Nope.string().required(),
age: Nope.number().required(),
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: nopeResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('name')} />
<input type="number" {...register('age')} />
<input type="submit" />
</form>
);
};TypeScript-first schema validation with static type inference
…Static and runtime type assertion library with no dependencies
…The fastest JSON validator for Node.js and browser
…JSON Schema Type Builder with Static Type Resolution for TypeScript
ValueCheck…TypeCompilerA high-performance JIT of TypeBox, read more
…t.Files())typeboxResolver validates using @sinclair/typebox's own Value.Errors/Value.Check, so any schema
Kind not built into TypeBox (custom types, or ones defined by a third-party library such as ElysiaJS)
must be registered with TypeBox's own TypeRegistry (and FormatRegistry for string formats) before
it's used — this is a TypeBox-level extension point, not something @hookform/resolvers wraps or needs
to expose separately:
import { TypeRegistry } from '@sinclair/typebox';
if (!TypeRegistry.Has('Files')) {
TypeRegistry.Set('Files', (schema, value) => Array.isArray(value));
}Make sure this registration runs against the same @sinclair/typebox module instance the schema was
built with — if a library vendors its own copy of @sinclair/typebox instead of relying on the shared
peer dependency, its registrations won't be visible here, and you'll see a runtime "Unknown type" error.
TypeScript's 1:1 validator, optimized from editor to runtime
import { useForm } from 'react-hook-form';
import { arktypeResolver } from '@hookform/resolvers/arktype';
import { type } from 'arktype';
const schema = type({
username: 'string>1',
password: 'string>1',
});
const App = () => {
const { register, handleSubmit } = useForm({
resolver: arktypeResolver(schema),
});
return (
<form onSubmit={handleSubmit((d) => console.log(d))}>
<input {...register('username')} />
<input type="password" {...register('password')} />
<input type="submit" />
</form>
);
};The modular and type safe schema library for validating structural data
…⚠️ If your schema uses
v.transform(...)(orv.pipe(..., v.transform(...))) on a field, that field's parsed output type can differ from what the user actually types (its input type) — e.g. a string input transformed into a number. Passing a single generic touseForm<T>pins both the submitted values and thehandleSubmitpayload to that one type, which conflicts withvalibotResolver, since it infers input and output separately. Either omit the generic and let it infer fromresolver, or specify all three explicitly:const schema = v.object({ name: v.string(), number: v.pipe(v.string(), v.transform(Number)), }); useForm<v.InferInput<typeof schema>, unknown, v.InferOutput<typeof schema>>({ reso
No open issues yet, or sync has not completed.