Skip to content

React Hook Form Resolver Not Working — Fix Schema Validation

DodaTech Updated 2026-06-24 2 min read

In this fix, you'll learn how to integrate schema validation with React Hook Form. This matters for form validation reliability, and appears in user registration and checkout forms.

The Problem

The following code demonstrates the typical mistake:

const schema = z.object({ email: z.string().email() });
const { register, handleSubmit, formState: { errors } } = useForm({
  // resolver not set — validation not working
});
// Form submits even with invalid email — no validation errors

The Fix

Here is the corrected version:

import { zodResolver } from '@hookform/resolvers/zod';
const schema = z.object({ email: z.string().email() });
const { register, handleSubmit, formState: { errors } } = useForm({
  resolver: zodResolver(schema),
});
// Form validation works — email errors appear

Prevention

  • Always pass a resolver option to useForm when using schema validation.
  • Install the correct resolver package for your schema library.
  • The resolver runs on change/submit — configure mode and reValidateMode.
  • Use TypeScript generics for typed forms: useForm({ resolver }).
  • Custom resolvers must return { values, errors } with the correct format.

Common Mistakes with hook form resolver

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [Char] with poor performance for large text operations

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What format must a custom resolver return?

A resolver receives form values and returns { values: TFieldValues, errors: DeepMap<TFieldValues, FieldError> }. Errors must match field paths with type and message properties.

When does the resolver run?

Default mode is 'onSubmit' (on form submission). With mode: 'onChange', it runs on every value change. With mode: 'onBlur', it runs when a field loses focus.

Can I use multiple resolvers together?

Only one resolver per form. For multi-step validation, swap the resolver between steps or use a single schema that combines all steps (like Zod's discriminated union).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro