react-hook-form
React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, useFieldArray, and the v7.55+ subscribe() API. This skill should be used when building client-side controlled forms with React Hook Form library. This skill does NOT cover React 19 Server Actions, useActionState, or server-side form handling (use react-19 skill for those).
- License 许可
- MIT
- 最近更新
- 2026-08-02
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- react-hook-form
- description
- React Hook Form performance optimization for client-side form validation using useForm, useWatch, useController, useFieldArray, and the v7.55+ subscribe() API. This skill should be used when building client-side controlled forms with React Hook Form library. This skill does NOT cover React 19 Server Actions, useActionState, or server-side form handling (use react-19 skill for those).
02 资源文件 48
- 参考文档AGENTS.md11.3 KB
- 资产文件assets/templates/_template.md591 B
- 参考文档references/_sections.md1.8 KB
- 参考文档references/adv-devtools-performance.md1.8 KB
- 参考文档references/adv-formprovider-memo.md2.0 KB
- 参考文档references/adv-testing-wrapper.md1.8 KB
- 参考文档references/array-complete-default-objects.md1.9 KB
- 参考文档references/array-separate-crud-operations.md2.0 KB
- 参考文档references/array-unique-fieldarray-per-name.md1.7 KB
- 参考文档references/array-use-field-id-as-key.md1.7 KB
- 参考文档references/array-virtualization-formprovider.md1.8 KB
- 参考文档references/ctrl-avoid-double-registration.md1.3 KB
- 参考文档references/ctrl-controller-field-props.md1.7 KB
- 参考文档references/ctrl-local-state-combination.md2.0 KB
- 参考文档references/ctrl-single-usecontroller-per-component.md1.8 KB
- 参考文档references/ctrl-usecontroller-isolation.md2.8 KB
- 参考文档references/formcfg-async-default-values.md1.8 KB
- 参考文档references/formcfg-default-values.md1.7 KB
- 参考文档references/formcfg-disabled-prop.md3.3 KB
- 参考文档references/formcfg-revalidate-mode.md2.3 KB
- 参考文档references/formcfg-should-unregister.md1.8 KB
- 参考文档references/formcfg-useeffect-dependency.md1.5 KB
- 参考文档references/formcfg-validation-mode.md1.6 KB
- 参考文档references/formstate-async-submit-lifecycle.md3.5 KB
- 参考文档references/formstate-avoid-isvalid-with-onsubmit.md1.7 KB
- 参考文档references/formstate-destructure-formstate.md1.3 KB
- 参考文档references/formstate-getfieldstate-for-single-field.md1.6 KB
- 参考文档references/formstate-subscribe-to-specific-fields.md1.5 KB
- 参考文档references/formstate-useformstate-isolation.md1.8 KB
- 参考文档references/integ-mui-controller-pattern.md1.6 KB
- 参考文档references/integ-shadcn-form-import.md1.6 KB
- 参考文档references/integ-shadcn-select-wiring.md1.9 KB
- 参考文档references/integ-value-transform.md1.5 KB
- 参考文档references/sub-avoid-watch-in-render.md1.6 KB
- 参考文档references/sub-deep-subscription.md2.0 KB
- 参考文档references/sub-subscribe-outside-react.md3.2 KB
- 参考文档references/sub-useformcontext-sparingly.md1.6 KB
- 参考文档references/sub-usewatch-default-value.md1.3 KB
- 参考文档references/sub-usewatch-over-watch.md1.9 KB
- 参考文档references/sub-usewatch-with-getvalues.md1.5 KB
- 参考文档references/sub-watch-specific-fields.md1.8 KB
- 参考文档references/valid-delay-error.md1.4 KB
- 参考文档references/valid-dynamic-schema-factory.md1.7 KB
- 参考文档references/valid-error-message-strategy.md1.8 KB
- 参考文档references/valid-inline-vs-resolver.md1.9 KB
- 参考文档references/valid-native-validation.md1.7 KB
- 参考文档references/valid-resolver-caching.md1.6 KB
- 参考文档references/valid-server-errors.md3.6 KB
03 SKILL.md 正文
React Hook Form Best Practices by Community
Comprehensive performance optimization guide for React Hook Form applications. Contains 45 rules across 8 categories, prioritized by impact to guide form development, automated refactoring, and code generation.
When to Apply
Reference these guidelines when:
- Writing new forms with React Hook Form
- Configuring useForm options (mode, defaultValues, validation)
- Subscribing to form values with watch / useWatch / subscribe
- Integrating controlled UI components (MUI, shadcn, Ant Design)
- Managing dynamic field arrays with useFieldArray
- Handling async submit, server errors, and submit lifecycle state
- Reviewing forms for performance issues
When NOT to Use This Skill
- React 19 Server Actions /
useActionState— use thereact-19skill instead - Deeply nested, fully type-safe forms — TanStack Form may be a better fit for forms with complex nested schemas; this skill assumes you've already chosen RHF
- Single-input or trivial forms — uncontrolled
<form>+FormDatais often simpler than pulling in any library
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Form Configuration | CRITICAL | formcfg- |
| 2 | Field Subscription | CRITICAL | sub- |
| 3 | Controlled Components | HIGH | ctrl- |
| 4 | Validation Patterns | HIGH | valid- |
| 5 | Field Arrays | MEDIUM-HIGH | array- |
| 6 | State Management | MEDIUM | formstate- |
| 7 | Integration Patterns | MEDIUM | integ- |
| 8 | Advanced Patterns | LOW | adv- |
Quick Reference
1. Form Configuration (CRITICAL)
formcfg-validation-mode- Use onSubmit mode for optimal performanceformcfg-revalidate-mode- Consider reValidateMode for expensive validationformcfg-default-values- Always provide defaultValues for form initializationformcfg-async-default-values- Use async defaultValues for server dataformcfg-should-unregister- Enable shouldUnregister for dynamic form memory efficiencyformcfg-useeffect-dependency- Avoid useForm return object in useEffect dependenciesformcfg-disabled-prop- Understand that register's disabled prop clears the value
2. Field Subscription (CRITICAL)
sub-usewatch-over-watch- Use useWatch instead of watch for isolated re-renderssub-watch-specific-fields- Watch specific fields instead of entire formsub-subscribe-outside-react- Use subscribe() for non-UI side-effects (analytics, autosave)sub-usewatch-with-getvalues- Combine useWatch with getValues for timing safetysub-deep-subscription- Subscribe deep in component tree where data is neededsub-avoid-watch-in-render- Avoid calling watch() in render for one-time readssub-usewatch-default-value- Provide defaultValue to useWatch for initial rendersub-useformcontext-sparingly- Use useFormContext sparingly for deep nesting
3. Controlled Components (HIGH)
ctrl-usecontroller-isolation- Isolate controlled inputs in dedicated child componentsctrl-avoid-double-registration- Avoid double registration with useControllerctrl-controller-field-props- Wire Controller field props correctly for UI librariesctrl-single-usecontroller-per-component- Use single useController per componentctrl-local-state-combination- Combine local state with useController for UI-only state
4. Validation Patterns (HIGH)
valid-resolver-caching- Define schema outside component for resolver cachingvalid-server-errors- Surface server errors via setError('root.serverError', ...)valid-dynamic-schema-factory- Use schema factory for dynamic validationvalid-error-message-strategy- Access errors via optional chaining or lodash getvalid-inline-vs-resolver- Prefer resolver over inline validation for complex rulesvalid-delay-error- Use delayError to debounce rapid error displayvalid-native-validation- Consider native validation for simple forms
5. Field Arrays (MEDIUM-HIGH)
array-use-field-id-as-key- Use field.id as key in useFieldArray mapsarray-complete-default-objects- Provide complete default objects for field array operationsarray-separate-crud-operations- Separate sequential field array operationsarray-unique-fieldarray-per-name- Use single useFieldArray instance per field namearray-virtualization-formprovider- Use FormProvider for virtualized field arrays
6. State Management (MEDIUM)
formstate-async-submit-lifecycle- Wrap async submit handlers in try/catch and reset on isSubmitSuccessfulformstate-destructure-formstate- Destructure formState properties before renderformstate-useformstate-isolation- Use useFormState for isolated state subscriptionsformstate-getfieldstate-for-single-field- Use getFieldState for single field state accessformstate-subscribe-to-specific-fields- Subscribe to specific field names in useFormStateformstate-avoid-isvalid-with-onsubmit- Avoid isValid with onSubmit mode for button state
7. Integration Patterns (MEDIUM)
integ-shadcn-form-import- Verify shadcn Form component import sourceinteg-shadcn-select-wiring- Wire shadcn Select with onValueChange instead of spreadinteg-mui-controller-pattern- Use Controller for Material-UI componentsinteg-value-transform- Transform values at Controller level for type coercion
8. Advanced Patterns (LOW)
adv-formprovider-memo- Wrap FormProvider children with React.memoadv-devtools-performance- Disable DevTools in production and during performance testingadv-testing-wrapper- Create test wrapper with QueryClient and AuthProvider
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Reference files:
references/{prefix}-{slug}.md
Related Skills
- For schema validation with Zod resolver, see
zodskill - For React 19 server actions, see
react-19skill - For UI/UX form design, see
frontend-designskill
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
04 同仓库更多 Skills
zustand
Rules and standards for state management using Zustand in React and Next.js. Use when implementing client-side stores, persistence with localStorage, or preventing SSR hydration mismatch.
zod
Zod v4 schema validation best practices. Use when defining schemas, utilizing safeParse, or customizing error messages.
upstash-ratelimit
Rules, standards, and references for rate limiting in serverless environments using Upstash Ratelimit. Use when implementing rate limiting, configuring Upstash Redis, or handling request blocking.
ui-design
UI/UX and frontend design best practices guidelines (formerly frontend-design). This skill should be used when writing, reviewing, or designing frontend code to ensure accessibility, performance, and usability. Triggers on tasks involving HTML structure, CSS styling, responsive layouts, form design, animations, or accessibility improvements.
typescript
TypeScript performance, tsconfig, type errors, async patterns — triggered when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
typescript-refactor
TypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should be used when refactoring, reviewing, or modernizing TypeScript or React/TSX code for type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving type architecture, narrowing, generics, discriminated unions, error handling, React component and hook typing, or migration to modern TypeScript features (satisfies, using, const type parameters, inferred type predicates, isolatedDeclarations, erasable syntax, import attributes).