With React 19 Compiler: memoization may be inserted automatically — avoid manual React.memo/useMemo until you verify the compiler does not handle it.
Details
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.
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: react-memoization-pattern3description: React Memoization Pattern4---5# React Memoization Pattern67> Prevent expensive re-renders and recomputations with React memoization APIs89## When to Use1011- A child component re-renders with the same props because the parent re-renders (use `React.memo`)12- A derived value is computationally expensive and its inputs rarely change (use `useMemo`)13- A callback function reference must be stable to avoid breaking `React.memo` on child components (use `useCallback`)14- You have profiled the component with React DevTools and confirmed unnecessary renders1516## Instructions17181. **Profile first.** Do not memoize without evidence of a problem — premature memoization adds code complexity and can hurt performance if used incorrectly.192. Wrap a component with `React.memo` to skip re-render when props are shallowly equal:20 ```typescript21 const ExpensiveList = React.memo(function ExpensiveList({ items }: { items: Item[] }) {22 return <ul>{items.map((i) => <li key={i.id}>{i.name}</li>)}</ul>;23 });24 ```253. Use `useMemo` for expensive computations:26 ```typescript27 const sortedItems = useMemo(() => [...items].sort(compareFn), [items]);28 ```294. Use `useCallback` for stable callback references:30 ```typescript31 const handleClick = useCallback(() => onSelect(id), [id, onSelect]);32 ```335. With React 19 Compiler: memoization may be inserted automatically — avoid manual `React.memo`/`useMemo` until you verify the compiler does not handle it.3435## Details3637Memoization trades memory for computation. React's memoization hooks cache values between renders when dependency arrays are unchanged.3839**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.4041**`useMemo` vs `useCallback`:**4243- `useMemo` memoizes a computed value: `useMemo(() => compute(), [dep])`44- `useCallback` memoizes a function: `useCallback(() => fn(), [dep])` — equivalent to `useMemo(() => () => fn(), [dep])`4546**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.4748**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.4950## Source5152https://patterns.dev/react/memoization-pattern5354## Process55561. Read the instructions and examples in this document.572. Apply the patterns to your implementation, adapting to your specific context.583. Verify your implementation against the details and edge cases listed above.5960## Harness Integration6162- **Type:** knowledge — this skill is a reference document, not a procedural workflow.63- **No tools or state** — consumed as context by other skills and agents.6465## Success Criteria6667- The patterns described in this document are applied correctly in the implementation.68- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/react-memoization-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
React Memoization Pattern It is listed under Web & Frontend on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.