react-hook-form

? React custom hook for form validation without the hassle

Github星跟踪图

npm downloads
npm
dep
npm
Coverage Status

Tweet Join the community on Spectrum

??English, ?? 简体中文, ?? 日本語, ??한국어, ??Français, ??Italiano, ??Português, ??Español, ??Русский

Features

  • Built with performance and DX in mind
  • Embrace uncontrolled form validation
  • Improve controlled form's performance
  • Tiny size without any dependency
  • Follows HTML standard for validation
  • Compatible with React Native
  • Supports Yup, Joi, Superstruct or custom
  • Supports native browser validation
  • Build forms quickly with the form builder

Install

$ npm install react-hook-form

Quickstart

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} /> {/* 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>
  );
}

Backers

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

Contributors

Thanks goes to these wonderful people. [Become a contributor].

主要指标

概览
名称与所有者react-hook-form/react-hook-form
主编程语言TypeScript
编程语言TypeScript (语言数: 4)
平台
许可证MIT License
所有者活动
创建于2019-03-05 23:47:10
推送于2025-04-24 21:55:09
最后一次提交2025-04-25 07:54:38
发布数719
最新版本名称v7.56.1 (发布于 2025-04-23 07:49:52)
第一版名称v0.0.2 (发布于 2019-03-17 20:00:08)
用户参与
星数42.9k
关注者数174
派生数2.2k
提交数3.8k
已启用问题?
问题数4728
打开的问题数68
拉请求数2014
打开的拉请求数45
关闭的拉请求数454
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?