Forms in React with React Hook Form
Build performant, accessible forms with React Hook Form: registration, validation, errors, arrays and submission states.
Intermediate · about 4 hours · difficulty 3/5
Learn first: HTML Forms and Native Validation, Hooks, Refs and State Patterns
Forms are where users give you money and data, so they deserve care. Handling every field with useState gets verbose and re-renders on every keystroke. React Hook Form (RHF) keeps inputs mostly uncontrolled, re-renders only what needs it and gives you a tidy API for validation and errors.
The basics
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<FormValues>().<input {...register("email", { required: "Email is required" })} />wires up a field.handleSubmit(onSubmit)validates, then calls your function with typed values.ControlleroruseControllerintegrates controlled components such as date pickers and custom selects.useFieldArrayhandles repeating groups (multiple addresses, line items).- Pair it with a schema resolver (Zod) so validation rules live in one typed place.
UX that matters
- Label every input with
<label>; do not rely on placeholders. - Validate on blur or submit, not on every keystroke from the first character.
- Show errors next to the field, connect them with
aria-describedbyand setaria-invalid. - Move focus to the first invalid field on submit (RHF does this by default).
- Disable double submits, show progress, and keep the user's input after a server error.
- Map server-side validation errors back to fields with
setError.
Alternatives
TanStack Form (type-safe, framework-agnostic), Formik (older codebases) and native forms with React 19 Actions for simple cases.
Good enough to move on
You can build a multi-field signup form with a dynamic field array, schema validation, accessible error messages and server error mapping.
Key concepts
- useForm and register
- handleSubmit and submission state
- Displaying errors accessibly
- Controller for custom inputs
- useFieldArray
- Mapping server errors with setError
- TanStack Form and Formik
Mini project
Build an invoice editor form: customer details, a dynamic list of line items with computed totals, a custom date picker via Controller and server-side error mapping from a mock API.
Check yourself
Why does React Hook Form re-render less than a form built from one useState per field?
Free resources
- React Hook Form Get Started (React Hook Form)
- TanStack Form (TanStack)
- Forms tutorial (W3C WAI)