Zod Validation Error Not Showing— react-hook-form Fixed [2026]
Also covers: zodResolver setup · formState.errors · nested errors · custom messages · onChange vs onBlur mode
⚡ The Problem
// 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
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?.messageWhy 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.
Add zodResolver to useForm
Root cause — Zod not connected to react-hook-formnpm 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>
)
}Display Errors from formState.errors
Errors object exists but nothing shown in UIAccess errors with errors.fieldName?.message — the optional chaining handles undefined safely. Display the message string below each field.
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>
)
}Fix Nested Object and Array Validation Errors
errors.address.city.message — nested field errorsFor nested schemas, errors mirror the schema structure. Access nested errors with dot-notation chaining.
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")} />Add Custom Zod Error Messages
Default messages too generic — customise per fieldimport { 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
}
)Trigger Validation on Blur vs Submit
Errors only show after submit — configure mode// 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 fieldsFor 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
- Always install @hookform/resolvers and add resolver: zodResolver(schema) to useForm
- Access errors with errors.fieldName?.message — the optional chaining prevents undefined crashes
- Use z.infer<typeof schema> for the form type — keeps TypeScript and Zod in sync automatically
- Add custom error messages to every Zod validator — defaults like 'String must contain at least 1 character(s)' confuse users
- Use mode: 'onBlur' and reValidateMode: 'onChange' for the best validation UX
- For nested schemas, access errors with dot notation: errors.address?.city?.message
Frequently Asked Questions
Why are my Zod validation errors not showing up?+−
How do I show Zod validation errors next to form fields?+−
Why does formState.errors show the error object but not the message?+−
How do I show errors for nested Zod objects?+−
What is the difference between mode: 'onChange' and mode: 'onSubmit' in react-hook-form?+−
Can I use Zod validation without react-hook-form?+−
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