react-hook-form

README

Get started |    API |   Form Builder |   FAQs |   Examples

Features


Built with performance, UX and DX in mind
Embraces native HTML form validation
Out of the box integration with UI libraries
Small size and no dependencies
Support Yup, Zod, AJV, Superstruct, Joi and others

Install


  1. ``` sh
  2. npm install react-hook-form

  3. ```

Quickstart


  1. ``` js
  2. import { useForm } from 'react-hook-form';

  3. function App() {
  4.   const {
  5.     register,
  6.     handleSubmit,
  7.     formState: { errors },
  8.   } = useForm();

  9.   return (
  10.     <form onSubmit={handleSubmit((data) => console.log(data))}>
  11.       <input {...register('firstName')} />
  12.       <input {...register('lastName', { required: true })} />
  13.       {errors.lastName && <p>Last name is required.</p>}
  14.       <input {...register('age', { pattern: /\d+/ })} />
  15.       {errors.age && <p>Please enter number for age.</p>}
  16.       <input type="submit" />
  17.     </form>
  18.   );
  19. }
  20. ```

Sponsors


Thanks go to these kind and lovely sponsors!

Backers


Thanks go to all our backers! [Become a backer ].

Contributors


Thanks go to these wonderful people! [Become a contributor ].