d25d482dc2
CI / Migrate DB (push) Blocked by required conditions
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Blocked by required conditions
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Blocked by required conditions
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Blocked by required conditions
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Blocked by required conditions
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Blocked by required conditions
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Blocked by required conditions
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Blocked by required conditions
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Blocked by required conditions
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Blocked by required conditions
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Blocked by required conditions
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Blocked by required conditions
CI / Check Docs Changes (push) Waiting to run
CI / Process Docs (push) Blocked by required conditions
CI / Create GitHub Release (push) Blocked by required conditions
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Blocked by required conditions
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Blocked by required conditions
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Blocked by required conditions
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Blocked by required conditions
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Blocked by required conditions
CI / Detect Version (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Deploy Trigger.dev (Dev) (push) Waiting to run
CI / Test and Build (push) Has started running
3.2 KiB
3.2 KiB
description: Analyze and fix useCallback anti-patterns in your code argument-hint: [scope] [fix=true|false]
You Might Not Need a Callback
Arguments:
- scope: what to analyze (default: your current changes). Examples: "diff to main", "PR #123", "src/components/", "whole codebase"
- fix: whether to apply fixes (default: true). Set to false to only propose changes.
User arguments: $ARGUMENTS
References
Read before analyzing:
- https://react.dev/reference/react/useCallback — official docs on when useCallback is actually needed
The one rule that matters
useCallback is only useful when something observes the reference. Ask: does anything care if this function gets a new identity on re-render?
Observers that care about reference stability:
- A
useEffectthat lists the function in its deps array - A
useMemothat lists the function in its deps array - Another
useCallbackthat lists the function in its deps array - A child component wrapped in
React.memothat receives the function as a prop
If none of those apply — if the function is only called inline, or passed to a non-memoized child, or assigned to a native element event — the reference is unobserved and useCallback adds overhead with zero benefit.
Anti-patterns to detect
- No observer tracks the reference: The function is only called inline in the same component, or passed to a non-memoized child, or used as a native element handler (
<button onClick={fn}>). Nothing re-runs or bails out based on reference identity. RemoveuseCallback. - useCallback with deps that change every render: If a dep is a plain object/array created inline, or state that changes on every interaction, memoization buys nothing — the function gets a new identity anyway.
- useCallback on handlers passed only to native elements:
<button onClick={fn}>— React never does reference equality on native element props. No benefit. - useCallback wrapping functions that return new objects/arrays: Stable function identity, unstable return value — memoization is at the wrong level. Use
useMemoon the return value instead, or restructure. - useCallback with empty deps when deps are needed: Stale closure — reads initial values forever. This is a correctness bug, not just a performance issue.
- Pairing useCallback + React.memo on trivially cheap renders: If the child renders in < 1ms and re-renders rarely, the memo infrastructure costs more than it saves.
Patterns that ARE correct — do not flag
useCallbackwhose result is in auseEffectdep array — prevents the effect from re-running on every renderuseCallbackwhose result is in auseMemodep array — prevents the memo from recomputing on every renderuseCallbackwhose result is a dep of anotheruseCallback— stabilises a callback chainuseCallbackpassed to aReact.memo-wrapped child — the whole point of the pattern- This codebase's ref pattern:
useRef+ callback with empty deps that reads the ref inside — correct, do not flag
Steps
- Read the reference above
- Analyze the specified scope for the anti-patterns listed above
- If fix=true, apply the fixes. If fix=false, propose the fixes without applying.