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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?