Form Handling in Next.js
— NextJS, Forms, React Hook Form, Zod — 2 min read
Form Handling in Next.js 2026 – The Approach I Use
Hey everyone,
Forms are still one of the parts that most often turn code into a mess when they're not handled well. After trying various approaches, here's the stack and pattern I use most often now.
1. My Main Stack
- React Hook Form → performant & flexible
- Zod → schema validation + type inference
- Server Actions → submit directly to the server
- shadcn/ui → clean form components
2. The Pattern I Use
"use client";
import { useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";import { createUser } from "./actions";
const schema = z.object({ name: z.string().min(2), email: z.string().email(),});
type FormData = z.infer<typeof schema>;
export function CreateUserForm() { const form = useForm<FormData>({ resolver: zodResolver(schema), });
const onSubmit = async (data: FormData) => { const result = await createUser(data); if (result?.error) { // handle error } };
return <form onSubmit={form.handleSubmit(onSubmit)}>{/* fields */}</form>;}3. A Clean Server Action
"use server";
import { z } from "zod";
const schema = z.object({ name: z.string().min(2), email: z.string().email(),});
export async function createUser(data: z.infer<typeof schema>) { const parsed = schema.safeParse(data); if (!parsed.success) { return { error: "Invalid data" }; }
// save to database return { success: true };}4. The Principles I Follow
- Validate on both the client and the server (don't trust the client alone)
- Use the same schema on the client & server whenever possible
- Give clear feedback (loading, error, success)
- Don't over-complicate a simple form
5. Things I Avoid
- Manually controlled inputs for large forms
- Validation only on the frontend
- Error messages that are too technical for the user
Conclusion
The combination of React Hook Form + Zod + Server Actions is still the most solid choice for me in 2026. Type-safe, performant, and flexible enough for almost every use case.
A question for you all: What form library are you using these days? Still on React Hook Form, or have you switched to something else?
Share your thoughts in the comments!
— Ady Rahmansyah
Software Engineer | Tech Blogger | Coffee Addict