- Được xây dựng với hiệu suất, trải nghiệm người dùng và sự phát triển dễ dàng trong tâm trí
- Chấp nhận biểu mẫu HTML nguyên thủy validation
- Tích hợp sẵn với UI libraries
- Small size và không cần phụ thuộc
- Hỗ trợ Yup, Zod, AJV, Superstruct, Joi và others
Cài đặt
npm install react-hook-form
Khởi đầu Nhanh
import { useForm } from 'react-hook-form';
function App() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm();
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input {...register('firstName')} />
<input {...register('lastName', { required: true })} />
{errors.lastName && <p>Last name is required.</p>}
<input {...register('age', { pattern: /\d+/ })} />
{errors.age && <p>Please enter number for age.</p>}
<input type="submit" />
</form>
);
}
.eslintignore
/app
/examples
/node_modules
/dist
/coverage
/src/types/global.d.ts
!.*.js
/reports
/scripts/README
.eslintrc
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "react-hooks", "simple-import-sort"],
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:cypress/recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"curly": "error",
"no-extra-boolean-cast": "error",
"cypress/unsafe-to-chain-command": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{ "ignoreRestSiblings": true }
],
"cypress/no-unnecessary-waiting": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
"react/display-name": "warn",
"react/prop-types": "off",
"no-console": ["error"],
"simple-import-sort/imports": [
"error",
{
"groups": [
// Side effect imports.
["^\\u0000"],
// Packages. `react` related packages come first.
["^react", "^@?\\w"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
]
}
],
"simple-import-sort/exports": "error"
},
"overrides": [
{
"files": ["*.test.ts", "*.test.tsx"],
"rules": {
// Allow testing runtime errors to suppress TS errors
"@typescript-eslint/ban-ts-comment": "off"
}
}
],
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
}
}
.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Coverage directory used by tools like istanbul
coverage
# Dependency directories
node_modules/
app/node_modules/
example/node_modules/
example/build/
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
.DS_Store
/lib
/dist
/temp
.idea/
.rpt2_cache
package-lock.json
/cypress/videos
/cypress/parallel-weights.json
/cypress/screenshots
/cypress/fixtures
Get started | API | Form Builder | FAQs | Examples
Chi tiết Tải về:
Tác giả: react-hook-form
Nguồn: https://github.com/react-hook-form/react-hook-form
Giấy phép: MIT license