Performant, flexible and extensible forms with easy-to-use validation
open sourceMITself-hostablefree
React Hook Form is a form library for React and React Native built around hooks and uncontrolled inputs: register connects native inputs as uncontrolled components to keep re-renders few, and Controller connects component libraries such as MUI or React-Select. It validates with HTML-standard rules (required, min, max, pattern) or a schema through @hookform/resolvers, which has resolvers for Zod, Yup, Valibot, ArkType, Joi, TypeBox, Ajv and any Standard Schema library and infers the form's value types from the schema. useFieldArray manages dynamic lists of fields, and useWatch, useFormState and useFormContext subscribe nested components to just what they need. It has no dependencies and is MIT licensed.
Problems it solves
- my React form re-renders on every keystroke and gets sluggish with dozens of fields
- add and remove rows of inputs in a React form, like line items or extra phone numbers
- get the TypeScript type of my form values from the same schema that validates them
- hook MUI, shadcn/ui or React-Select inputs up to form state and validation
- validate a form with simple rules like required, min length and pattern without writing handlers
- show validation errors after the user leaves a field or submits, not while they type
- use the same form state and validation code in React Native as on the web
- show or hide parts of a form depending on what was picked in another field
- put errors returned by my API on the right fields after submit
- enable the save button only when the form has changed and is valid
- nested components need the form's methods without passing props through every level
- reset a form to new default values after loading a record from the server
- reorder, insert and swap rows in a dynamic list of form fields
- build reusable typed input components that each focus on one part of a big form
- manage form state outside React components and share it with them
- debug which fields are dirty, touched or invalid while building a form
Features
- useForm with register for uncontrolled inputs and few re-renders
- built-in rules: required, min, max, minLength, maxLength, pattern, validate
- schema validation through @hookform/resolvers: Zod, Yup, Valibot, ArkType, Joi, Superstruct, TypeBox, Ajv, Effect, VineJS, Standard Schema and more
- resolvers infer the form's input and output types from the schema
- Controller and useController for controlled UI components
- useFieldArray: append, prepend, insert, remove, swap, move, update and replace rows
- useWatch, useFormState and useFormContext / FormProvider to isolate re-renders
- useLens for type-safe reusable field components
- createFormControl to create form control outside React
- Form component that posts to an endpoint
View 3 more
- React Native support
- DevTools package (@hookform/devtools)
- no dependencies
Limitations
- Doesn't support flat field arrays: each entry in a useFieldArray must be an object, not a string or number1
Alternatives
The same job
These do what React Hook Form does.
- TanStack Form Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, and Lit
