Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Teaches correct React Hook Form usage across the monorepo, covering subscriptions, reset, dirty state, number inputs and controlled inputs.
68% 91%+23 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 15 of 22 without it.
We need to log form value changes to an analytics provider without causing extra component re-renders. A developer wrote `form.watch((value) => sendAnalytics(value))` inside the component body. What is the correct API for render-free subscription listeners in React Hook Form?
Uses subscribe instead of watch for render-free listener callbacks.
This test ran on v2. v4 is the current version and hasn’t been tested on gemini-3.6-flash yet.
3 of 3 safety checks passed
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.
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:
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.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).useForm owner: destructure formState; use useWatch over form.watch (no-use-watch flags every watch, and useWatch scopes re-renders if extracted later).control (not form) and use useWatch({ control, name }) / useFormState({ control }), or read via useFormContext() + useWatch({ name }) inside <Form {...form}>.getValues() — the two lists drift and disagree within a render. Always pass name to useWatch so you don't subscribe to every field.watch(callback) is deprecated: use subscribe() for render-free listeners and return its cleanup from useEffect.// ❌ subscriptions hoist to the form owner and read paths drift
function Fields({ form }: { form: UseFormReturn<FormValues> }) {
form.watch(['storageType', 'totalSize'])
const { errors } = form.formState
const size = form.getValues('totalSize')
}
// ✅ child subscribes for itself and consumes what it watches
Next to this one in the catalogue, plus more from the same author.