Skip to content

skillFrontendreact

React Performance Optimization

Finds needless React re-renders with the Profiler and adds memoization only where a measurement shows it pays off.

npx workspacetemplates add react-performance-optimization --tool claude-code

Writes 1 file to .claude/skills/react-performance-optimization/

.claude/skills/react-performance-optimization/SKILL.md33 lines · 1.8 KBFile
---
name: react-performance-optimization
description: Finds needless React re-renders with the Profiler and adds memoization only where a measurement shows it pays off.
---

# React performance optimization

Measure, find the cause, make the smallest change, measure again.

## Steps

1. Reproduce the slow interaction and describe it precisely (typing, scroll, route change). Record a Profiler trace for it, or add a temporary `<Profiler onRender>` and log `actualDuration`. Note the baseline in milliseconds and render counts.
2. Identify the top offenders: components rendering most often or taking longest. For each ask why it rendered (state change, parent render, context change, new prop identity). Use "Highlight updates" or `why-did-you-render` if installed.
3. Fix in this order:
   - Move state down to the component that needs it, or lift expensive static children up as `children`.
   - Split a context so consumers of one value do not re-render for another.
   - Stabilize props only where a memoized child receives them: `useCallback` and `useMemo` for functions and objects.
   - Wrap a component in `React.memo` only when the profile shows it re-renders with unchanged props and costs real time.
   - Virtualize long lists (react-window or TanStack Virtual) instead of memoizing rows.
   - Use `useDeferredValue` or `startTransition` for expensive filtering from an input.
   - Split heavy routes with `lazy` and `Suspense`.
4. Never use array index as key for reorderable lists; use stable ids.
5. Re-profile and compare against the baseline.

## Rules

- No optimization without a number before and after.
- Remove any memo or callback wrapper that did not move the number.
- Do not mutate state to avoid renders.

## Report

Baseline versus result, each change with the reason, and the changes you tried and reverted.

What it does

Wrapping every component in memo makes code harder to read and often changes nothing. This skill starts with a measurement: what renders, how often, and how long it takes, and only then touches the code.

The agent fixes state placement and unstable props first, since that removes most work for free. Memoization, virtualization or code splitting follow only for the hot spots the profile identifies.

Example

you › Typing in the search box is laggy on the products page

agent › Baseline: 38 ms per keystroke, 214 ProductCard renders. Cause: query state lived in the page and re-rendered every card. Moved it into SearchBox, passed the debounced term down, and wrapped ProductCard in memo (the card was re-rendering with unchanged props). Result: 4 ms per keystroke, 12 renders. Reverted two useMemo calls with no effect.

Questions

Does it need the React DevTools?
The Profiler gives the best data, but the agent can also use the built-in Profiler component and console timings in a test run.
Why would it remove memoization?
Wrappers that do not change measured time still add code and risk stale values, so the agent takes them out.
  • Bundle Size Reduction

    Skilljavascript

    Free