The PR “cleans up” a form by wrapping every event handler in useCallback and every derived boolean in useMemo. The commit message says “performance.” There is no profile, no skipped render that mattered, and two stale-closure bugs in the validation path.
I’ve started treating agent-added useMemo / useCallback without a stated reason as noise, not as an optimization. React is not cheaper just because the call site looks official. The wrappers are extra dependencies to get wrong.
Why the wrap is usually cargo cult
The model has been trained on a lot of “always memoize callbacks passed to children” advice. Some of that advice was aimed at class components, or at a child wrapped in memo that actually sits in a hot list. A one-off <Button onClick={...}> in a settings page is not that situation.
useMemo also lies about cost. Memoizing a boolean const isEmpty = items.length === 0 is slower to think about than the comparison. Memoizing a big filtered list can be real — if the input is large and the parent renders often. That sentence should be in the PR, not implied by the hook.
Stale closures show up when the dependency array omits a function or a piece of form state. The memo was added to help, and now a submit handler sees yesterday’s values.
A simple memo policy
-
No
useMemo/useCallbackby default in agent PRs - Allowed when the PR names the expensive child or the measured cost
-
memoon a list row is a reason to stabilize props; a random button is not - Derived data first — a selector or a cheap variable, then memo only if needed
If the team already has a lint rule (react-hooks, react/no-unstable-nested-components), the agent should follow it, not pre-empt it with wrappers everywhere.
What to put in the prompt
Do not add useMemo or useCallback unless you can name the expensive render or the memoized child that depends on referential identity.
Do not wrap simple booleans, className strings, or one-off click handlers.
If you do memoize, include the reason in the PR body and list the dependencies carefully.
In review, if the hook was not there before the bugfix, ask whether the bugfix still works with the hook removed. Many times it does.
A useful exception is a context provider that passes a large value object into a wide tree. Stabilizing that value can be real work. Stabilizing a click handler on a leaf button, in the same PR, is still decoration. If the agent “also memoized the context value,” make it show the provider file and the consumers, not a blanket hook pass.
useMemo is not a substitute for moving expensive work out of render — a filter over 20,000 rows belongs in a worker, a query library, or a precomputed index, not in a hook that still runs on the main thread the first time.
Reject / send back
Reject
- A blanket “performance pass” that only adds memos
-
useMemo(() => items.length === 0, [items])as decoration - A stale-closure bug introduced by a new dependency array
- Memoizing something that is immediately passed into a non-memoized host component
Accept
- A memo whose PR note names the expensive list, chart, or memoized child
- A removed memo that was already doing nothing
- A real profile or render-count note, even a rough one
Top comments (0)