react-hook-form
React Hook Form Best Practices
Comprehensive performance optimization guide for React Hook Form applications. Contains 41 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
- Integrating controlled UI components (MUI, shadcn, Ant Design)
- Managing dynamic field arrays with useFieldArray
- Reviewing forms for performance issues
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- Set reValidateMode to onBlur for post-submit performanceformcfg-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 dependencies
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-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- Use useController for re-render isolationctrl-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-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-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
More from midudev/autoskills
bun
Use when building, testing, and deploying JavaScript/TypeScript applications. Reach for Bun when you need to run scripts, manage dependencies, bundle code, or test applications with a single unified tool.
13pydantic
Python data validation using type hints and runtime type checking with Pydantic v2's Rust-powered core for high-performance validation in FastAPI, Django, and configuration management.
9azure-deploy
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: \"run azd up\", \"run azd deploy\", \"execute deployment\", \"push to production\", \"push to cloud\", \"go live\", \"ship it\", \"bicep deploy\", \"terraform apply\", \"publish to Azure\", \"launch on Azure\". DO NOT USE WHEN: \"create and deploy\", \"build and deploy\", \"create a new app\", \"set up infrastructure\", \"create and deploy to Azure using Terraform\" — use azure-prepare for these.
8scikit-learn
Machine learning in Python with scikit-learn. Use when working with supervised learning (classification, regression), unsupervised learning (clustering, dimensionality reduction), model evaluation, hyperparameter tuning, preprocessing, or building ML pipelines. Provides comprehensive reference documentation for algorithms, preprocessing techniques, pipelines, and best practices.
8clerk
Clerk authentication router. Use when user asks about adding authentication,
8python-background-jobs
Python background job patterns including task queues, workers, and event-driven architecture. Use when implementing async task processing, job queues, long-running operations, or decoupling work from request/response cycles.
8