--- 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: 1. 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 `useEffect` that lists the function in its deps array - A `useMemo` that lists the function in its deps array - Another `useCallback` that lists the function in its deps array - A child component wrapped in `React.memo` that 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 1. **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 (`