react-hook-form-6
Version:
Latest version 6 of react-hook-form
274 lines (243 loc) • 10.4 kB
Markdown
<div align="center">
<p align="center">
<a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
<img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/logo.png" alt="React Hook Form Logo - React hook custom hook for form validation" width="300px" />
</a>
</p>
</div>
<p align="center">Performant, flexible and extensible forms with easy to use validation.</p>
<div align="center">
[](https://www.npmjs.com/package/react-hook-form)
[](https://www.npmjs.com/package/react-hook-form)
[](https://github.com/react-hook-form/react-hook-form/blob/master/LICENSE)
[](https://discord.gg/yYv7GZ8)
</div>
<div align="center">
<p align="center">
<a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
<img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/example.gif" alt="React Hook Form video - React custom hook for form validation" width="100%" />
</a>
</p>
</div>
English | <a href="./docs/README.zh-TW.md">繁中</a> | <a href="./docs/README.zh-CN.md">简中</a> | <a href="./docs/README.ja-JP.md">日本語</a> | <a href="./docs/README.ko-KR.md">한국어</a> | <a href="./docs/README.fr-FR.md">Français</a> | <a href="./docs/README.it-IT.md">Italiano</a> | <a href="./docs/README.pt-BR.md">Português</a> | <a href="./docs/README.es-ES.md">Español</a> | <a href="./docs/README.ru-RU.md">Русский</a> | <a href="./docs/README.de-DE.md">Deutsch</a> | <a href="./docs/README.tr-TR.md">Türkçe</a>
## Features
- Built with performance and DX in mind
- Embrace native form validation
- Simple integration with [UI libraries](https://codesandbox.io/s/react-hook-form-v6-controller-qsd8r)
- [Tiny size](https://bundlephobia.com/result?p=react-hook-form@latest) without any dependency
- Follows HTML standard for [validation](https://react-hook-form.com/get-started#Applyvalidation)
- [Resolvers](https://github.com/react-hook-form/resolvers) support [Yup](https://github.com/jquense/yup), [Zod](https://github.com/vriad/zod), [Superstruct](https://github.com/ianstormtaylor/superstruct), [Joi](https://github.com/hapijs/joi) or custom
- Build forms quickly with [Form Builder](https://react-hook-form.com/form-builder)
## Install
npm install react-hook-form
## Links
- [Motivation](https://medium.com/@bruce1049/form-validation-with-hook-in-3kb-c5414edf7d64)
- [Video tutorial](https://www.youtube.com/watch?v=-mFXqOaqgZk&t)
- [Get started](https://react-hook-form.com/get-started)
- [API](https://react-hook-form.com/api)
- [Examples](https://github.com/bluebill1049/react-hook-form/tree/master/examples)
- [Demo](https://react-hook-form.com)
- [Form Builder](https://react-hook-form.com/form-builder)
- [FAQs](https://react-hook-form.com/faqs)
## Quickstart
```jsx
import React from 'react';
import { useForm } from 'react-hook-form';
function App() {
const { register, handleSubmit, errors } = useForm(); // initialize the hook
const onSubmit = (data) => {
console.log(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstname" ref={register} /> {/* register an input */}
<input name="lastname" ref={register({ required: true })} />
{errors.lastname && 'Last name is required.'}
<input name="age" ref={register({ pattern: /\d+/ })} />
{errors.age && 'Please enter number for age.'}
<input type="submit" />
</form>
);
}
```
<a href="https://ui.dev/bytes/?r=bill">
<img src="https://raw.githubusercontent.com/react-hook-form/react-hook-form/master/docs/ads-1.jpg" />
</a>
## Sponsors
Thanks go to these kind and lovely sponsors (company and individuals)!
<a href="https://underbelly.is/" target="_blank">
<img src="https://images.opencollective.com/underbelly/989a4a6/logo/256.png" width="84" height="84" />
</a>
<p>
<a href="https://github.com/sayav"
><img
src="https://avatars1.githubusercontent.com/u/42376060?s=60&v=4"
width="40"
height="40"
alt="@sayav"
/></a>
<a href="https://github.com/lemcii"
><img
src="https://avatars1.githubusercontent.com/u/35668113?s=60&v=4"
width="40"
height="40"
alt="@lemcii"
/></a>
<a href="https://github.com/washingtonsoares"
><img
src="https://avatars0.githubusercontent.com/u/5726140?s=460&u=b300a6fa08a24c59b9db6ebf246384cf8b16a140&v=4"
width="40"
height="40"
alt="@washingtonsoares"
/></a>
<a href="https://github.com/lixunn"
><img
src="https://avatars0.githubusercontent.com/u/4017964?s=460&u=3a3fdffeb97749d7509d9c5e9be2cafcb98e426f&v=4"
width="40"
height="40"
alt="@lixunn"
/></a>
<a href="https://github.com/SamSamskies"
><img
src="https://avatars2.githubusercontent.com/u/3655410?s=60&v=4"
width="40"
height="40"
alt="@SamSamskies"
/></a>
<a href="https://github.com/peaonunes"
><img
src="https://avatars2.githubusercontent.com/u/3356720?s=60&v=4"
width="40"
height="40"
alt="@peaonunes"
/></a>
<a href="https://github.com/wilhelmeek"
><img
src="https://avatars2.githubusercontent.com/u/609452?s=60&v=4"
width="40"
height="40"
alt="@wilhelmeek"
/></a>
<a href="https://github.com/iwarner"
><img
src="https://avatars2.githubusercontent.com/u/279251?s=60&v=4"
width="40"
height="40"
alt="@iwarner"
/></a>
<a href="https://github.com/joejknowles"
><img
src="https://avatars2.githubusercontent.com/u/10728145?s=60&v=4"
width="40"
height="40"
alt="@joejknowles"
/></a>
<a href="https://github.com/chris-gunawardena"
><img
src="https://avatars0.githubusercontent.com/u/5763108?s=60&v=4"
width="40"
height="40"
alt="@chris-gunawardena"
/></a>
<a href="https://github.com/Tymek"
><img
src="https://avatars1.githubusercontent.com/u/2625371?s=60&v=4"
width="40"
height="40"
alt="@Tymek"
/></a>
<a href="https://github.com/Luchanso"
><img
src="https://avatars0.githubusercontent.com/u/2098777?s=60&v=4"
width="40"
height="40"
alt="@Luchanso"
/></a>
<a href="https://github.com/vcarel"
><img
src="https://avatars1.githubusercontent.com/u/1541093?s=60&v=4"
width="40"
height="40"
alt="@vcarel"
/></a>
<a href="https://github.com/gragland"
><img
src="https://avatars0.githubusercontent.com/u/1481077?s=60&v=4"
width="40"
height="40"
alt="@gragland"
/></a>
<a href="https://github.com/tjshipe"
><img
src="https://avatars2.githubusercontent.com/u/1254942?s=60&v=4"
width="40"
height="40"
alt="@tjshipe"
/></a>
<a href="https://github.com/krnlde"
><img
src="https://avatars1.githubusercontent.com/u/1087002?s=60&v=4"
width="40"
height="40"
alt="@krnlde"
/></a>
<a href="https://github.com/msutkowski"
><img
src="https://avatars2.githubusercontent.com/u/784953?s=60&v=4"
width="40"
height="40"
alt="@msutkowski"
/></a>
<a href="https://github.com/mlukaszczyk"
><img
src="https://avatars3.githubusercontent.com/u/599247?s=60&v=4"
width="40"
height="40"
alt="@mlukaszczyk"
/></a>
<a href="https://github.com/susshma"
><img
src="https://avatars0.githubusercontent.com/u/2566818?s=460&u=754ee26b96e321ff28dbc4a2744132015f534fe0&v=4"
width="40"
height="40"
/></a>
<a href="https://github.com/MatiasCiccone"
><img
src="https://avatars3.githubusercontent.com/u/32602795?s=460&u=6a0c4dbe23c4f9a5628dc8867842b75989ecc4aa&v=4"
width="40"
height="40"
/></a>
<a href="https://github.com/ghostwriternr"
><img
src="https://avatars0.githubusercontent.com/u/10023615?s=460&u=3ec1e4ba991699762fd22a9d9ef47a0599f937dc&v=4"
width="40"
height="40"
/></a>
<a href="https://github.com/neighborhood999"
><img
src="https://avatars3.githubusercontent.com/u/10325111?s=400&u=f60c932f81d95a60f77f5c7f2eab4590e07c29af&v=4"
width="40"
height="40"
/></a>
<a href="https://github.com/yjp20"
><img
src="https://avatars3.githubusercontent.com/u/44457064?s=460&u=a55119c84e0167f6a3f830dbad3133b28f0c0a8f&v=4"
width="40"
height="40"
/></a>
</p>
## Backers
Thanks go to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)].
<a href="https://opencollective.com/react-hook-form#backers">
<img src="https://opencollective.com/react-hook-form/backers.svg?width=950" />
</a>
## Organizations
Thanks go to these wonderful organizations! [[Contribute](https://opencollective.com/react-hook-form/contribute)].
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
<img src="https://opencollective.com/react-hook-form/organizations.svg?width=890" />
</a>
## Contributors
Thanks go to these wonderful people! [[Become a contributor](CONTRIBUTING.md)].
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
<img src="https://opencollective.com/react-hook-form/contributors.svg?width=890&button=false" />
</a>