docs/README.zh-CN.md
</a>
</p>
高性能、灵活、易拓展、易于使用的表单校验库
</div> <div align="center"><p align="center"><a href="https://react-hook-form.com/zh" title="React Hook Form - Simple React forms validation"></a></p></div><a href="./README.V6.md">English</a> | <a href="./README.zh-TW.md">繁中</a> | 简中 | <a href="./README.ja-JP.md">日本語</a> | <a href="./README.ko-KR.md">한국어</a> | <a href="./README.fr-FR.md">Français</a> | <a href="./README.it-IT.md">Italiano</a> | <a href="./README.pt-BR.md">Português</a> | <a href="./README.es-ES.md">Español</a> | <a href="./README.ru-RU.md">Русский</a> | <a href="./README.de-DE.md">Deutsch</a> | <a href="./README.tr-TR.md">Türkçe</a>
$ npm install react-hook-form
import React from 'react';
import { useForm } from 'react-hook-form';
function App() {
const { register, handleSubmit, errors } = useForm(); // initialise the hook
const onSubmit = (data) => {
console.log(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstname" ref={register} />
<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://opencollective.com/react-hook-form#backers"> </a>感谢这些精彩的组织! [捐助]
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors"> </a>感谢这些出色的人! [成为贡献者].
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors"> </a>