SWE-Skills-Bench / react-hook-form-patterns
AGENTS.md8 starsChanged 26 days agoMITView on GitHub
Version 1.2.0 Community May 2026 Note: This document targets React Hook Form codebases. It is mainly for agents and LLMs to follow when maintaining, generating, or refactoring forms. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows. Comprehensive performance optimization guide for React Hook Form applications, designed for AI agents and LLMs. Contains 45 rules across 8 categories, prioritized by impact from critical (form configuration, field subscriptions, async submit lifecycle) to…
1 other project uses a version of this.
Adopted by
Most recently taken up by
- krivoox/agent-stack-templateword for word, first seen Aug 14, 2026
Other versions1 project uses a version of this.
Word for word · 1
- krivoox/agent-stack-template★ 31100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository99 other files it gives its agents.
- skills/zod-schema-validation/AGENTS.mdAGENTS.md
- Add Admin API EndpointSkill
- add-malli-schemasSkill
- add-uint-supportSkill
- analytics-eventsSkill
- analyze-ciSkill
- asyncio-patternsSkill
- axum-web-patternsSkill
- bash-defensive-patternsSkill
- bats-shell-testingSkill
- bazel-build-optimizationSkill
- beautifulsoup-parsingSkill
- changelog-automationSkill
- cheerio-parsingSkill
- clap-cli-patternsSkill
- clojure-writeSkill
- cobra-cli-developmentSkill
- creating-financial-modelsSkill
- dbt-transformation-patternsSkill
- distributed-tracingSkill
- django-patternsSkill
- drizzle-orm-patternsSkill
- fastapi-patternsSkill
- fastify-patternsSkill
- fixSkill
- github-actions-templatesSkill
- gitlab-ci-patternsSkill
- gitops-workflowSkill
- go-cache-hotSkill
- go-concurrency-patternsSkill
- go-errors-oopsSkill
- go-fx-diSkill
- go-monads-moSkill
- go-swagger-codegenSkill
- go-testify-patternsSkill
- grafana-dashboardsSkill
- graphql-schema-designSkill
- grpc-service-definitionSkill
- hono-patternsSkill
- implementing-agent-modesSkill
- implementing-jsc-classes-zigSkill
- istio-traffic-managementSkill
- jest-advanced-patternsSkill
- junit5-testingSkill
- k8s-manifest-generatorSkill
- kysely-query-builderSkill
- langsmith-fetchSkill
- linkerd-patternsSkill
- llm-evaluationSkill
- mcp-builderSkill
- mypy-type-checkingSkill
- networkx-graph-algorithmsSkill
- nx-workspace-patternsSkill
- pandas-dataframe-patternsSkill
- pillow-image-processingSkill
- polars-dataframeSkill
- prisma-schema-patternsSkill
- prometheus-configurationSkill
- prompt-engineering-patternsSkill
- pydicom-dicom-parsingSkill
- The first 60 shown.
The file
Files
React Hook Form
Version 1.2.0
Community
May 2026
Note: This document targets React Hook Form codebases. It is mainly for agents and LLMs to follow when maintaining, generating, or refactoring forms. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows.
Abstract
Comprehensive performance optimization guide for React Hook Form applications, designed for AI agents and LLMs. Contains 45 rules across 8 categories, prioritized by impact from critical (form configuration, field subscriptions, async submit lifecycle) to incremental (advanced patterns). Covers the v7.55+ subscribe() API, server error handling via setError('root.*'), and the disabled register option. Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics to guide automated refactoring and code generation.
Table of Contents
- Form Configuration — CRITICAL
- 1.1 Always Provide defaultValues for Form Initialization — CRITICAL (prevents undefined state bugs and enables reset() functionality)
- 1.2 Avoid useForm Return Object in useEffect Dependencies — CRITICAL (prevents infinite render loops)
- 1.3 Enable shouldUnregister for Dynamic Form Memory Efficiency — HIGH (reduces memory usage for forms with frequently mounted/unmounted fields)
- 1.4 Consider reValidateMode for Expensive Validation — MEDIUM (trade-off between immediate corrective feedback and validation cost)
- 1.5 Understand That register's disabled Prop Clears the Value — MEDIUM (prevents lost field values and silently skipped validation)
- 1.6 Use Async defaultValues for Server Data — CRITICAL (eliminates manual useEffect reset patterns)
- 1.7 Use onSubmit Mode for Optimal Performance — CRITICAL (prevents re-renders on every keystroke)
- Field Subscription — CRITICAL
- 2.1 Avoid Calling watch() in Render for One-Time Reads — HIGH (prevents unnecessary subscriptions and re-renders)
- 2.2 Combine useWatch with getValues for Timing Safety — HIGH (prevents missed updates due to subscription timing)
- 2.3 Provide defaultValue to useWatch for Initial Render — MEDIUM-HIGH (prevents undefined flash on initial render)
- 2.4 Subscribe Deep in Component Tree Where Data Is Needed — CRITICAL (prevents parent re-renders from propagating to unrelated children)
- 2.5 Use subscribe() to React to Form Changes Outside the React Lifecycle — HIGH (zero re-renders for non-UI consumers like analytics, autosave, telemetry)
- 2.6 Use useFormContext Sparingly for Deep Nesting — MEDIUM (reduces prop drilling but increases implicit dependencies)
- 2.7 Use useWatch Instead of watch for Isolated Re-renders — CRITICAL (reduces re-renders by 10-50× in complex forms with multiple watchers)
- 2.8 Watch Specific Fields Instead of Entire Form — CRITICAL (reduces re-renders from N fields to 1 field change)
- Controlled Components — HIGH
- 3.1 Avoid Double Registration with useController — HIGH (prevents duplicate state management and validation bugs)
- 3.2 Combine Local State with useController for UI-Only State — MEDIUM (reduces form re-renders by 50%+ when UI state changes don't affect form data)
- 3.3 Use Single useController Per Component — MEDIUM-HIGH (prevents prop name collisions and simplifies component logic)
- 3.4 Isolate Controlled Inputs in Dedicated Child Components — HIGH (reduces re-renders from O(n) to O(1) per field change)
- 3.5 Wire Controller Field Props Correctly for UI Libraries — HIGH (prevents form binding bugs and eliminates silent failures in 100% of UI library integrations)
- Validation Patterns — HIGH
- 4.1 Access Errors via Optional Chaining or Lodash Get — MEDIUM-HIGH (prevents runtime errors from undefined nested properties)
- 4.2 Consider Native Validation for Simple Forms — MEDIUM (reduces JavaScript validation overhead for basic constraints)
- 4.3 Define Schema Outside Component for Resolver Caching — HIGH (prevents schema recreation on every render)
- 4.4 Prefer Resolver Over Inline Validation for Complex Rules — HIGH (centralizes validation logic and enables type inference)
- 4.5 Surface Server Errors via setError('root.serverError', ...) — HIGH (prevents lost server-side validation errors and unrecoverable form state)
- 4.6 Use delayError to Debounce Rapid Error Display — MEDIUM (reduces UI flicker during fast typing validation)
- 4.7 Use Schema Factory for Dynamic Validation — HIGH (enables context-dependent validation without render-time schema creation)
- Field Arrays — MEDIUM-HIGH
- 5.1 Provide Complete Default Objects for Field Array Operations — HIGH (prevents partial data and validation failures)
- 5.2 Separate Sequential Field Array Operations — MEDIUM-HIGH (prevents state corruption from batched mutations)
- 5.3 Use field.id as Key in useFieldArray Maps — MEDIUM-HIGH (prevents state corruption and unnecessary re-renders)
- 5.4 Use FormProvider for Virtualized Field Arrays — MEDIUM (maintains field state when rows exit/enter viewport)
- 5.5 Use Single useFieldArray Instance Per Field Name — MEDIUM-HIGH (prevents state conflicts from duplicate subscriptions)
- State Management — MEDIUM
- 6.1 Avoid isValid with onSubmit Mode for Button State — MEDIUM (prevents validation on every render for button disabled state)
- 6.2 Destructure formState Properties Before Render — MEDIUM (enables Proxy subscription optimization)
- 6.3 Subscribe to Specific Field Names in useFormState — MEDIUM (reduces re-renders to only relevant field changes)
- 6.4 Use getFieldState for Single Field State Access — MEDIUM (avoids subscription overhead for one-time state reads)
- 6.5 Use useFormState for Isolated State Subscriptions — MEDIUM (prevents parent re-renders from state access in children)
- 6.6 Wrap Async Submit Handlers in try/catch and Reset on isSubmitSuccessful — HIGH (prevents stuck isSubmitting state and missing post-success reset)
- Integration Patterns — MEDIUM
- 7.1 Transform Values at Controller Level for Type Coercion — MEDIUM (prevents type coercion bugs in 100% of numeric/date form fields)
- 7.2 Use Controller for Material-UI Components — MEDIUM (maintains controlled component behavior with proper event handling)
- 7.3 Verify shadcn Form Component Import Source — MEDIUM (prevents silent component mismatch bugs)
- 7.4 Wire shadcn Select with onValueChange Instead of Spread — MEDIUM (prevents 100% of silent select binding failures with Radix-based components)
- Advanced Patterns — LOW
- 8.1 Create Test Wrapper with QueryClient and AuthProvider — LOW (enables proper hook testing with required context providers)
- 8.2 Disable DevTools in Production and During Performance Testing — LOW (eliminates DevTools overhead during profiling)
- 8.3 Wrap FormProvider Children with React.memo — LOW (prevents cascade re-renders from FormProvider state updates)
References
- https://react-hook-form.com/docs
- https://react-hook-form.com/advanced-usage
- https://react-hook-form.com/docs/useform
- https://react-hook-form.com/docs/useform/subscribe
- https://react-hook-form.com/docs/useform/seterror
- https://react-hook-form.com/docs/useform/formstate
- https://react-hook-form.com/docs/usewatch
- https://react-hook-form.com/docs/usecontroller
- https://react-hook-form.com/docs/usefieldarray
- https://react-hook-form.com/docs/useformstate
- https://github.com/react-hook-form/resolvers
- https://ui.shadcn.com/docs/components/form
Source Files
This document was compiled from individual reference files. For detailed editing or extension:
| File | Description |
| references/_sections.md | Category definitions and impact ordering |
| assets/templates/_template.md | Template for creating new rules |
| SKILL.md | Quick reference entry point |
| metadata.json | Version and reference URLs |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

