ZodReact Hook FormError Fix2026 Updated

Zod Validation Error Not Showing— react-hook-form Fixed [2026]

Also covers: zodResolver setup · formState.errors · nested errors · custom messages · onChange vs onBlur mode

January 20266 min readZod v3 · react-hook-form · TypeScript

⚡ The Problem

Error
// Form submits without errors — Zod schema never runs
const { register, handleSubmit, formState: { errors } } = useForm()
// errors is always {} — zodResolver not connected!

// OR: errors object has error but message is undefined
console.log(errors.email)         // { type: 'too_small', ... }
console.log(errors.email.message) // undefined — accessing wrong level

✅ Fix — add zodResolver and access .message

Complete setup
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"

const schema = z.object({ email: z.string().email("Invalid email") })
type FormData = z.infer<typeof schema>

const { register, handleSubmit, formState: { errors } } = useForm<FormData>({
  resolver: zodResolver(schema),   // ← connect Zod
})
// Access error: errors.email?.message

Why Zod Errors Don't Appear in Your Form

Zod and react-hook-form are separate libraries. They are connected by @hookform/resolvers/zod. Without the zodResolver in useForm, react-hook-form runs its own basic built-in validation and never touches your Zod schema. The result is no validation errors or only HTML5 required-field errors.

1

Add zodResolver to useForm

Root cause — Zod not connected to react-hook-form
3 min
Install resolver and connect Zod
npm install @hookform/resolvers zod react-hook-form

// types/forms.ts — define schema and infer type
import { z } from "zod"

export const contactSchema = z.object({
  name: z.string().min(2, "Name must be at least 2 characters"),
  email: z.string().email("Please enter a valid email"),
  message: z.string().min(10, "Message must be at least 10 characters"),
  phone: z.string().optional(),
})
export type ContactFormData = z.infer<typeof contactSchema>

// components/contact-form.tsx
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { contactSchema, type ContactFormData } from "@/types/forms"

export function ContactForm() {
  const {
    register,
    handleSubmit,
    formState: { errors, isSubmitting },
  } = useForm<ContactFormData>({
    resolver: zodResolver(contactSchema),   // ← connects Zod to react-hook-form
    mode: "onBlur",                        // validate on blur, re-validate on change
  })

  const onSubmit = (data: ContactFormData) => {
    console.log("Valid data:", data)   // only runs if Zod validates successfully
  }

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      {/* fields with error display */}
    </form>
  )
}
2

Display Errors from formState.errors

Errors object exists but nothing shown in UI
3 min

Access errors with errors.fieldName?.message — the optional chaining handles undefined safely. Display the message string below each field.

Complete form with error display
export function ContactForm() {
  const { register, handleSubmit, formState: { errors } } = useForm<ContactFormData>({
    resolver: zodResolver(contactSchema),
  })

  return (
    <form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
      {/* Name field */}
      <div>
        <label className="block text-sm font-medium mb-1">Name</label>
        <input
          {...register("name")}
          className={`w-full border rounded px-3 py-2 ${errors.name ? "border-red-500" : "border-gray-300"}`}
        />
        {errors.name && (
          <p className="mt-1 text-sm text-red-600">{errors.name.message}</p>
        )}
      </div>

      {/* Email field */}
      <div>
        <label className="block text-sm font-medium mb-1">Email</label>
        <input
          {...register("email")}
          type="email"
          className={`w-full border rounded px-3 py-2 ${errors.email ? "border-red-500" : "border-gray-300"}`}
        />
        {errors.email && (
          <p className="mt-1 text-sm text-red-600">{errors.email.message}</p>
        )}
      </div>

      {/* Message field */}
      <div>
        <label className="block text-sm font-medium mb-1">Message</label>
        <textarea
          {...register("message")}
          className={`w-full border rounded px-3 py-2 ${errors.message ? "border-red-500" : "border-gray-300"}`}
        />
        {errors.message && (
          <p className="mt-1 text-sm text-red-600">{errors.message.message}</p>
        )}
      </div>

      <button type="submit" disabled={isSubmitting}>Submit</button>
    </form>
  )
}
3

Fix Nested Object and Array Validation Errors

errors.address.city.message — nested field errors
3 min

For nested schemas, errors mirror the schema structure. Access nested errors with dot-notation chaining.

Nested schema and error access
const addressSchema = z.object({
  name: z.string().min(1, "Name required"),
  address: z.object({
    street: z.string().min(1, "Street required"),
    city: z.string().min(1, "City required"),
    postcode: z.string().regex(/^d{5}$/, "Must be 5 digits"),
  }),
  tags: z.array(z.string()).min(1, "Add at least one tag"),
})

// Access nested errors:
// errors.address?.street?.message
// errors.address?.city?.message
// errors.tags?.message  (array-level error — too few items)
// errors.tags?.[0]?.message  (item-level error)

// In JSX:
{errors.address?.city && (
  <p className="text-red-600 text-sm">{errors.address.city.message}</p>
)}

// Register nested fields with dot notation:
<input {...register("address.city")} />
4

Add Custom Zod Error Messages

Default messages too generic — customise per field
2 min
Custom messages for every validation
import { z } from "zod"

const registerSchema = z.object({
  username: z
    .string()
    .min(3, "Username must be at least 3 characters")
    .max(20, "Username cannot exceed 20 characters")
    .regex(/^[a-z0-9_]+$/, "Only lowercase letters, numbers, and underscores"),

  email: z
    .string()
    .min(1, "Email is required")           // empty string check
    .email("Please enter a valid email address"),

  password: z
    .string()
    .min(8, "Password must be at least 8 characters")
    .regex(/[A-Z]/, "Must contain at least one uppercase letter")
    .regex(/[0-9]/, "Must contain at least one number"),

  confirmPassword: z.string(),

  age: z
    .number({ invalid_type_error: "Age must be a number" })
    .min(18, "You must be 18 or older")
    .max(120, "Please enter a valid age"),
}).refine(
  data => data.password === data.confirmPassword,
  {
    message: "Passwords do not match",
    path: ["confirmPassword"],    // which field the error appears on
  }
)
5

Trigger Validation on Blur vs Submit

Errors only show after submit — configure mode
2 min
Validation mode options
// mode: when initial validation runs
// reValidateMode: when re-validation runs after first error

// ✅ Best UX pattern:
const form = useForm<FormData>({
  resolver: zodResolver(schema),
  mode: "onBlur",               // first error shows when user leaves field
  reValidateMode: "onChange",   // error clears as user types a fix
})

// Options:
// mode: "onSubmit"    — default, only validates on submit
// mode: "onBlur"     — validates when field loses focus
// mode: "onChange"   — validates on every keystroke (can be noisy)
// mode: "all"        — both onChange and onBlur

// Manually trigger validation for a specific field:
const { trigger } = useForm({ resolver: zodResolver(schema) })
await trigger("email")    // validates just the email field
await trigger()           // validates all fields

For the best user experience: use mode: 'onBlur' so errors appear when the user moves to the next field, and reValidateMode: 'onChange' so the error message disappears as soon as the user fixes it.

Prevention

Frequently Asked Questions

Why are my Zod validation errors not showing up?+
The most common cause is missing the zodResolver in useForm. Without the resolver, react-hook-form uses its own basic validation and never runs your Zod schema. Add resolver: zodResolver(schema) to your useForm options to connect Zod to react-hook-form.
How do I show Zod validation errors next to form fields?+
Access errors through formState.errors from useForm. For each field, check errors.fieldName?.message and display it. The message is the string you set in your Zod schema with z.string().min(1, 'This field is required').
Why does formState.errors show the error object but not the message?+
Zod errors are nested — for a field named email, the error is at errors.email.message. If you see the error object but not the message string, you are probably accessing errors.email instead of errors.email?.message. Always access .message for the string.
How do I show errors for nested Zod objects?+
For a schema with a nested object like address: z.object({ city: z.string() }), access the nested error with errors.address?.city?.message. react-hook-form mirrors the schema structure in the errors object.
What is the difference between mode: 'onChange' and mode: 'onSubmit' in react-hook-form?+
mode controls when validation runs. onSubmit (default) only validates when the form is submitted. onChange validates on every keystroke. onBlur validates when the field loses focus. For the best UX, use mode: 'onBlur' for initial validation and reValidateMode: 'onChange' to fix errors as the user types.
Can I use Zod validation without react-hook-form?+
Yes. Call schema.safeParse(data) directly on any object. If success is false, access error.flatten().fieldErrors for a map of field names to error message arrays. This works for Server Actions, API route validation, or any plain JavaScript/TypeScript validation.

Need Expert Help?

We Build Forms with Zod + react-hook-form

Softplix engineers build type-safe, validated forms with Zod schemas, react-hook-form, and shadcn/ui — production ready. Let us help.

Talk to an Engineer