Skip to main content
⚡ OpenDevDocs
packagesformsReferenceIntermediate

React Hook Form: Performant Form State Management

Complete developer reference for React Hook Form, uncontrolled form inputs, Zod resolver integration, useForm, Controller, and performance optimization.

Verified: 2026-09-30
Tested on:react-hook-form 7.53.x, react 19.x, typescript 5.6.x
Platforms:
browserall
#react-hook-form#react#forms#zod

What It Is

React Hook Form is a performant, flexible, and extensible form state management library for React. It leverages uncontrolled form inputs with ref-based subscriptions to eliminate unnecessary component re-renders during user typing.


Why Use It

  1. Unmatched Performance: Reduces re-renders to near zero by subscribing to input changes without rerendering the parent form component on every keystroke.
  2. First-Class Schema Validation: First-class integration with schema validators (Zod, Yup, Valibot) via @hookform/resolvers.
  3. Tiny Footprint: Zero external dependencies and ultra-small bundle size (~8.5KB gzipped).
  4. Native HTML Constraint Integration: Seamlessly works with native HTML5 validation attributes (required, min, max, pattern).

Installation


Quick Start

"use client";

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

const formSchema = z.object({
  username: z.string().min(3, "Username must be at least 3 characters"),
  email: z.string().email("Invalid email address"),
  password: z.string().min(8, "Password must be at least 8 characters"),
});

type FormValues = z.infer<typeof formSchema>;

export function RegisterForm() {
  const {
    register,
    handleSubmit,
    formState: { errors, isSubmitting },
    reset,
  } = useForm<FormValues>({
    resolver: zodResolver(formSchema),
    defaultValues: {
      username: "",
      email: "",
      password: "",
    },
  });

  const onSubmit = async (data: FormValues) => {
    console.log("Form data submitted:", data);
    // await api.register(data);
    reset();
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)} className="space-y-4 max-w-md">
      <div>
        <label className="block text-sm font-medium">Username</label>
        <input
          {...register("username")}
          className="w-full px-3 py-2 border rounded"
        />
        {errors.username && (
          <p className="text-red-500 text-xs mt-1">{errors.username.message}</p>
        )}
      </div>

      <div>
        <label className="block text-sm font-medium">Email</label>
        <input
          type="email"
          {...register("email")}
          className="w-full px-3 py-2 border rounded"
        />
        {errors.email && (
          <p className="text-red-500 text-xs mt-1">{errors.email.message}</p>
        )}
      </div>

      <div>
        <label className="block text-sm font-medium">Password</label>
        <input
          type="password"
          {...register("password")}
          className="w-full px-3 py-2 border rounded"
        />
        {errors.password && (
          <p className="text-red-500 text-xs mt-1">{errors.password.message}</p>
        )}
      </div>

      <button
        type="submit"
        disabled={isSubmitting}
        className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50"
      >
        {isSubmitting ? "Submitting..." : "Register"}
      </button>
    </form>
  );
}

Common APIs

Hook / ComponentDescriptionExample
useForm(options)Main hook for registering fields, managing state, and handling submissionconst { register, handleSubmit } = useForm()
register(name, rules)Registers an HTML input element via ref<input {...register("email")} />
handleSubmit(onValid, onInvalid)Submits form after running validation<form onSubmit={handleSubmit(onSubmit)}>
ControllerWrapper component for controlled UI libraries (shadcn/ui, MUI, Radix)<Controller control={control} name="select" render={...} />
useFieldArrayManages dynamic list of form items (add, remove, swap, move)const { fields, append, remove } = useFieldArray(...)
useWatchSubscribes to isolated field updates without rerendering entire formconst role = useWatch({ control, name: "role" })
reset(values)Resets form state and default valuesreset()

Controlled Component Example (Controller)

When using custom third-party UI components (e.g. Radix UI Select, DatePicker):

import { useForm, Controller } from "react-hook-form";
import Select from "react-select";

export function ControlledSelectForm() {
  const { control, handleSubmit } = useForm();

  return (
    <form onSubmit={handleSubmit(data => console.log(data))}>
      <Controller
        name="country"
        control={control}
        render={({ field }) => (
          <Select
            {...field}
            options={[
              { value: "us", label: "United States" },
              { value: "ca", label: "Canada" },
              { value: "bd", label: "Bangladesh" },
            ]}
          />
        )}
      />
      <button type="submit">Submit</button>
    </form>
  );
}

Best Practices

  1. Pair with Zod: Use zodResolver(schema) for type safety and complex validation logic.
  2. Isolate Dynamic Watching with useWatch: Avoid extracting values via watch() at the top level of large components to prevent root re-renders.
  3. Always Provide defaultValues: Prevents warnings regarding transitioning from uncontrolled to controlled input states.

Common Mistakes

  • Passing inline objects to defaultValues without memoization: Causes state reset loops if calculated dynamically inside render body.
  • Forgetting type="button" on sub-buttons: Any button inside a <form> defaults to type="submit" and triggers validation unexpectedly.

Alternatives

  • Formik: Classic React form library; uses controlled inputs resulting in more re-renders on large forms.
  • TanStack Form: Type-safe, headless form manager designed for React, Solid, Vue, and Svelte.
  • Conform: Progressive-enhancement form validation designed specifically for Remix and Next.js Server Actions.

When Not to Use It

  • Simple 1-field search inputs where native useState or uncontrolled <form action={...}> is sufficient.

Official Resources

On this page