React Hook Form Schema Migration

React Hook Form uses a resolver-based architecture that cleanly separates form handling from schema validation. This makes it one of the easiest form libraries to migrate between schema libraries — SchemaShift handles both the schema conversion and the resolver import rewriting in a single command.

Before & After

SchemaShift migrates both the schema definitions and the resolver imports. Here is a typical React Hook Form component before and after migrating from Yup to Zod:

Before (Yup)
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';

const schema = yup.object({
  email: yup.string().email().required(),
  password: yup.string().min(8).required(),
});

const { register, handleSubmit } = useForm({
  resolver: yupResolver(schema),
});
After (Zod)
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';

const schema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
});

const { register, handleSubmit } = useForm({
  resolver: zodResolver(schema),
});

Notice that both the schema library imports and the resolver function are rewritten automatically. The useForm call itself remains unchanged — only the resolver wrapper function changes.

Automatic Resolver Migration

SchemaShift's FormResolverMigrator detects @hookform/resolvers imports in your source files and rewrites them to match your target schema library. This happens automatically during any migration that involves a supported form library.

Supported Resolver Mappings

Migration Path Source Resolver Target Resolver
Yup → Zod yupResolver zodResolver
Joi → Zod joiResolver zodResolver
Zod → Valibot zodResolver valibotResolver
Zod → Yup zodResolver yupResolver
Valibot → Zod valibotResolver zodResolver

The import path is also updated (e.g., @hookform/resolvers/yup becomes @hookform/resolvers/zod).

Migration Command

No special flags are needed — resolver migration is automatic when SchemaShift detects React Hook Form in your project:

# Preview changes first
schemashift migrate ./src -f yup -t zod --dry-run

# Run the migration
schemashift migrate ./src -f yup -t zod

# Use the react-hook-form preset for guided migration
schemashift migrate ./src --preset react-hook-form-yup-to-zod
Migration Preset

The react-hook-form-yup-to-zod preset is a built-in migration template that configures optimal settings for React Hook Form projects. Use schemashift presets to see all available templates.

Edge Cases & Gotchas

After Migration

FAQ

How do I migrate React Hook Form from Yup to Zod?

Run schemashift migrate ./src -f yup -t zod and SchemaShift will automatically detect React Hook Form usage, convert your Yup schemas to Zod, and rewrite yupResolver imports to zodResolver. Make sure @hookform/resolvers is updated to a version that supports Zod. Use --dry-run first to preview changes.

Does SchemaShift handle resolver imports automatically?

Yes. SchemaShift's FormResolverMigrator detects resolver imports from @hookform/resolvers and rewrites them to match your target schema library. It handles yupResolver to zodResolver, joiResolver to zodResolver, and zodResolver to valibotResolver automatically.

Do I need to update @hookform/resolvers separately?

Yes. After migrating your schemas, ensure @hookform/resolvers is at a version that includes the resolver for your target library. SchemaShift rewrites the import statements, but you should run npm install @hookform/resolvers@latest to get the latest resolver support. The package has included zodResolver since v3.0.0.

Related Migration Guides

Get Started

React Hook Form's resolver architecture makes schema migration straightforward. SchemaShift handles both the schema conversion and resolver rewriting automatically.

npm install -g schemashift-cli

Resolver migration requires the Individual tier or above. View pricing.