--- name: you-might-not-need-a-callback description: Analyze and fix useCallback anti-patterns in your code --- # 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 ## When useCallback IS needed - Passing a callback to a child wrapped in `React.memo` (to preserve referential equality) - The callback is a dependency of another hook (`useEffect`, `useMemo`) - The callback is used in a custom hook that documents referential stability requirements ## Anti-patterns to detect 1. **useCallback on functions not passed as props or deps**: If the function is only called within the same component and isn't in any dependency array, useCallback adds overhead for no benefit. Just declare the function normally. 2. **useCallback with exhaustive deps that change every render**: If the dependency array includes values that change on every render, useCallback recalculates every time. The memoization is wasted. Either stabilize the deps (use refs) or remove the useCallback. 3. **useCallback on event handlers passed to native elements**: `