Skip to content

Latest commit

 

History

History
81 lines (61 loc) · 4.03 KB

README.zh-CN.md

File metadata and controls

81 lines (61 loc) · 4.03 KB

React Hook Form Logo - React hook form validation

高性能、灵活、易拓展、易于使用的表单校验库

CircleCI npm downloads npm dep npm Coverage Status

Tweet Join the community on Spectrum

React Hook Form Logo - React hook form validation

🇦🇺English | 🇨🇳 简体中文 | 🇯🇵 日本語 | 🇰🇷한국어 | 🇫🇷Français | 🇮🇹Italiano | 🇧🇷Português | 🇪🇸Español | 🇷🇺Русский

特性

  • 使创建表单和集成更加便捷
  • 以性能和开发体验为基础构建
  • 非受控表单校验
  • 迷你的体积而没有其他依赖
  • 遵循 html 标准进行校验
  • 支持浏览器原生校验
  • 这里快速构建你的表单

安装

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

贡献者

感谢这些为该开源项目作出贡献的人: