install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/react-hook-form" ~/.claude/skills/comeonoliver-skillshub-react-hook-form && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/react-hook-form/SKILL.mdsource content
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 | |
| 2 | Field Subscription | CRITICAL | |
| 3 | Controlled Components | HIGH | |
| 4 | Validation Patterns | HIGH | |
| 5 | Field Arrays | MEDIUM-HIGH | |
| 6 | State Management | MEDIUM | |
| 7 | Integration Patterns | MEDIUM | |
| 8 | Advanced Patterns | LOW | |
Quick Reference
1. Form Configuration (CRITICAL)
- Use onSubmit mode for optimal performanceformcfg-validation-mode
- Set reValidateMode to onBlur for post-submit performanceformcfg-revalidate-mode
- Always provide defaultValues for form initializationformcfg-default-values
- Use async defaultValues for server dataformcfg-async-default-values
- Enable shouldUnregister for dynamic form memory efficiencyformcfg-should-unregister
- Avoid useForm return object in useEffect dependenciesformcfg-useeffect-dependency
2. Field Subscription (CRITICAL)
- Use useWatch instead of watch for isolated re-renderssub-usewatch-over-watch
- Watch specific fields instead of entire formsub-watch-specific-fields
- Combine useWatch with getValues for timing safetysub-usewatch-with-getvalues
- Subscribe deep in component tree where data is neededsub-deep-subscription
- Avoid calling watch() in render for one-time readssub-avoid-watch-in-render
- Provide defaultValue to useWatch for initial rendersub-usewatch-default-value
- Use useFormContext sparingly for deep nestingsub-useformcontext-sparingly
3. Controlled Components (HIGH)
- Use useController for re-render isolationctrl-usecontroller-isolation
- Avoid double registration with useControllerctrl-avoid-double-registration
- Wire Controller field props correctly for UI librariesctrl-controller-field-props
- Use single useController per componentctrl-single-usecontroller-per-component
- Combine local state with useController for UI-only statectrl-local-state-combination
4. Validation Patterns (HIGH)
- Define schema outside component for resolver cachingvalid-resolver-caching
- Use schema factory for dynamic validationvalid-dynamic-schema-factory
- Access errors via optional chaining or lodash getvalid-error-message-strategy
- Prefer resolver over inline validation for complex rulesvalid-inline-vs-resolver
- Use delayError to debounce rapid error displayvalid-delay-error
- Consider native validation for simple formsvalid-native-validation
5. Field Arrays (MEDIUM-HIGH)
- Use field.id as key in useFieldArray mapsarray-use-field-id-as-key
- Provide complete default objects for field array operationsarray-complete-default-objects
- Separate sequential field array operationsarray-separate-crud-operations
- Use single useFieldArray instance per field namearray-unique-fieldarray-per-name
- Use FormProvider for virtualized field arraysarray-virtualization-formprovider
6. State Management (MEDIUM)
- Destructure formState properties before renderformstate-destructure-formstate
- Use useFormState for isolated state subscriptionsformstate-useformstate-isolation
- Use getFieldState for single field state accessformstate-getfieldstate-for-single-field
- Subscribe to specific field names in useFormStateformstate-subscribe-to-specific-fields
- Avoid isValid with onSubmit mode for button stateformstate-avoid-isvalid-with-onsubmit
7. Integration Patterns (MEDIUM)
- Verify shadcn Form component import sourceinteg-shadcn-form-import
- Wire shadcn Select with onValueChange instead of spreadinteg-shadcn-select-wiring
- Use Controller for Material-UI componentsinteg-mui-controller-pattern
- Transform values at Controller level for type coercioninteg-value-transform
8. Advanced Patterns (LOW)
- Wrap FormProvider children with React.memoadv-formprovider-memo
- Disable DevTools in production and during performance testingadv-devtools-performance
- Create test wrapper with QueryClient and AuthProvideradv-testing-wrapper
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
skillzod - For React 19 server actions, see
skillreact-19 - For UI/UX form design, see
skillfrontend-design
Full Compiled Document
For the complete guide with all rules expanded:
AGENTS.md