useMemo caches a calculation between re-renders and is only a performance optimization
Answer: useMemo(calculateValue, dependencies) is a React Hook to cache the result of a calculation between re-renders. React compares each dependency with its previous value using Object.is and reuses the cached value if none changed.
Example
import { useMemo } from 'react';
function TodoList({ todos, filter }) {
const visibleTodos = useMemo(() => filterTodos(todos, filter), [todos, filter]);
return <List items={visibleTodos} />;
}
Rules
- Call it only at the top level of your component or Hooks, never inside loops or conditions.
- In Strict Mode, React calls your calculation function twice to help you find accidental impurities (development-only behavior).
- Rely on
useMemoonly as a performance optimization. If the code doesn't work without it, fix the underlying problem first.
When it pays off
Optimizing with useMemo is only valuable in a few cases: the calculation is noticeably slow and its dependencies rarely change, or you pass the value as a prop to a component wrapped in memo. If most interactions are granular, like moving shapes in a drawing editor, memoization can be very helpful.
Compiler note
In many cases React Compiler can automatically memoize expensive calculations, so manual useMemo is not needed. You can cache (or "memoize") an expensive calculation by wrapping it in a useMemo Hook.
See also
Claims
- id: C1 claim: useMemo caches a calculation result between re-renders. source: S1 evidence: "lets you cache the result of a calculation between re-renders"
- id: C2 claim: Dependencies are compared with Object.is. source: S1 evidence: "React will compare each dependency with its previous value using the Object.is comparison"
- id: C3 claim: useMemo should only be a performance optimization. source: S1 evidence: "You should only rely on useMemo as a performance optimization."
- id: C4 claim: React Compiler can memoize expensive calculations automatically. source: S2 evidence: "React Compiler can automatically memoize expensive calculations for you"
Sources
- [S1] useMemo. React docs (reference). https://react.dev/reference/react/useMemo . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] You Might Not Need an Effect. React docs (learn). https://react.dev/learn/you-might-not-need-an-effect . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: React docs (reference), useMemo; React docs (learn), You Might Not Need an Effect. CC-BY-4.0 (https://raw.githubusercontent.com/reactjs/react.dev/main/LICENSE-DOCS.md). Copyright Meta Platforms, Inc. and affiliates. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: React docs (reference), useMemo; React docs (learn), You Might Not Need an Effect. CC-BY-4.0 (https://raw.githubusercontent.com/reactjs/react.dev/main/LICENSE-DOCS.md). Copyright Meta Platforms, Inc. and affiliates.
Cite this
iinventedlight. 2026. "useMemo caches a calculation between re-renders and is only a performance optimization." iinventedlight Library, iil:note:sj3g1mj5, version of 2026-11-18. https://iinventedlight.com/library/notes/react-usememo/. License: CC-BY-4.0.
@misc{iil_note_sj3g1mj5,
author = {{iinventedlight}},
title = {{useMemo caches a calculation between re-renders and is only a performance optimization}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/react-usememo/},
note = {Permanent ID iil:note:sj3g1mj5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/react-usememo.md.