From harness-claude
Prevents expensive re-renders and recomputations with React memoization APIs. Covers React.memo, useMemo, useCallback, and React 19 Compiler.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:react-memoization-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Prevent expensive re-renders and recomputations with React memoization APIs
Prevent expensive re-renders and recomputations with React memoization APIs
React.memo)useMemo)React.memo on child components (use useCallback)React.memo to skip re-render when props are shallowly equal:
const ExpensiveList = React.memo(function ExpensiveList({ items }: { items: Item[] }) {
return <ul>{items.map((i) => <li key={i.id}>{i.name}</li>)}</ul>;
});
useMemo for expensive computations:
const sortedItems = useMemo(() => [...items].sort(compareFn), [items]);
useCallback for stable callback references:
const handleClick = useCallback(() => onSelect(id), [id, onSelect]);
React.memo/useMemo until you verify the compiler does not handle it.Memoization trades memory for computation. React's memoization hooks cache values between renders when dependency arrays are unchanged.
Shallow equality: React.memo uses shallow comparison — object/array props created inline always produce new references, breaking memoization. Pass stable references or memoize the props themselves.
useMemo vs useCallback:
useMemo memoizes a computed value: useMemo(() => compute(), [dep])useCallback memoizes a function: useCallback(() => fn(), [dep]) — equivalent to useMemo(() => () => fn(), [dep])React 19 Compiler: The React compiler automatically memoizes components and hooks. Manual React.memo, useMemo, and useCallback may become unnecessary in codebases using the compiler.
Anti-pattern: Wrapping every component in React.memo without profiling. Memo has overhead — the cost of comparison must be less than the cost of re-rendering.
https://patterns.dev/react/memoization-pattern
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeOptimizes React performance using React.memo for component memoization, custom prop comparisons, and useMemo for expensive computations like filtering and sorting. Use for preventing unnecessary re-renders.
Guides React component design with minimal state via derived values and props, atomic memoization, type-safe patterns, and optimized conditional logic. Use for creating components, state management, render optimization.
Diagnoses slow React components by identifying render hotspots, isolating expensive updates, and applying targeted optimizations like memoization and state splitting.