---
name: react-hook-form
description: Correct React Hook Form usage across the monorepo — data flow, subscriptions,
reset, dirty state, number inputs, and controlled-input rules. Load before writing or
editing any form, field, watch/useWatch/formState/getValues/setValue/reset, or
submit/cancel footer; older files contain anti-patterns. For layout and components, see
studio-ui-patterns.
---
# React Hook Form
The existing codebase is **not** a safe reference: `form.watch()` off prop-drilled form objects, subscription-only watches, unguarded `valueAsNumber`, and `?? undefined` controlled values are common in older code and all wrong. Follow this skill, not the neighboring file.
**Policy — fix what you touch.** New code must follow these rules. When modifying existing form code, upgrade the specific fields/hooks/components you touch (e.g. convert `form.watch` to `useWatch`). Leave untouched code alone, but mention anti-patterns you noticed. Never add new violations: `react-hook-form/no-use-watch` is an ESLint `error` in Studio CI.
## Mental model: subscriptions decide who re-renders
RHF is uncontrolled at heart. Values live in refs; nothing re-renders unless a subscription says so. Every read API is a subscription decision:
| API | Subscribes | Re-renders | Use for |
| ----------------------------- | ---------- | -------------------------- | ---------------------------------------------- |
| `useWatch({ control, name })` | yes | only the calling component | reactive value reads, anywhere |
| `useFormState({ control })` | yes | only the calling component | `isDirty`/`errors`/etc. outside the form owner |
| `formState` (destructured) | yes | the `useForm` owner | form state **in the owner component only** |
| `form.watch(name)` | yes | the **entire form tree** | avoid — lint-flagged, see below |
| `getValues()` | no | never | event handlers and `onSubmit` only |
| `subscribe()` | callback | none | side effects outside render |
Two facts explain most form bugs:
1. **`form.watch()` and `form.formState` hoist their subscription to the `useForm` owner**, no matter where they are called. A child calling `form.watch('x')` off a prop works only by re-rendering the entire tree on every keystroke and silently goes stale behind `React.memo`. A no-arg `form.watch()` re-renders the whole tree on every field change.
2. **`formState` is a Proxy** — reading a property arms the subscription. Destructure it (`const { isDirty } = form.formState`), never pass the object around or read it conditionally (`a && formState.isValid` may never subscribe). Enforced by `react-hook-form/destructuring-formstate` (error).
### Reading values, by location
- **In the `useForm` owner:** destructure `formState`; use `useWatch` over `form.watch` (`no-use-watch` flags every `watch`, and `useWatch` scopes re-renders if extracted later).
- **In any child component or custom hook:** pass `control` (not `form`) and use `useWatch({ control, name })` / `useFormState({ control })`, or read via `useFormContext()` + `useWatch({ name })` inside `