React useMemo: When to Use It and When to Avoid It

At a glance
Start with the slow interaction, such as typing into a filter over a large local list. Measure it in a production-like build with representative data. Then memoize only the expensive pure calculation and repeat the same interaction.
React components can render many times as state and props change. That does not automatically mean your app is slow. Most small calculations are inexpensive, and adding memoization everywhere can make code harder to understand without making the interface noticeably faster.
useMemo lets React reuse the result of a calculation between renders while its dependencies remain unchanged. This guide explains when it is useful, when it is unnecessary, and how to verify the difference rather than optimizing by guesswork.
A measurement that can justify keeping useMemo
Start with the slow interaction, such as typing into a filter over a large local list. Measure it in a production-like build with representative data. Then memoize only the expensive pure calculation and repeat the same interaction.
Check that changing every relevant input still updates the output. A missing dependency can make a faster interface display stale results. A newly created object in the dependency list can force recalculation every render and remove the expected benefit.
If the calculation is cheap or the measured improvement is negligible, simpler code may be preferable. Never rely on the memoized value for correctness: the component must work when React recalculates it. Do not put network requests, state updates or other side effects in the calculation.
Reference: React useMemo documentation.
What does useMemo do?
useMemo takes a calculation function and a dependency array:
const result = useMemo(() => calculateSomething(input), [input]);
React runs the calculation on the initial render. On later renders, it can reuse the previous result if the dependencies compare equal using Object.is. If a dependency changes, React recalculates the value.
The cached result is a performance optimization, not a place to store state or perform side effects. The calculation should be pure: it should return a value without changing external state.
Official reference: https://react.dev/reference/react/useMemo
Example: Filtering a large product list
Suppose a component filters products as a user types:
import { useMemo, useState } from "react";
export default function ProductSearch({ products }) {
const [query, setQuery] = useState("");
const filteredProducts = useMemo(() => {
const normalizedQuery = query.trim().toLowerCase();
return products.filter((product) =>
product.name.toLowerCase().includes(normalizedQuery)
);
}, [products, query]);
return (
<section>
<label>
Search products
<input
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder="Type a product name"
/>
</label>
<ul>
{filteredProducts.map((product) => (
<li key={product.id}>{product.name}</li>
))}
</ul>
</section>
);
}
This example demonstrates the API, but it does not prove memoization is needed. If products contains only a few entries, the normal filter may already be fast enough. Use the React Profiler or a simple timing experiment to find out whether the calculation affects user experience.
When useMemo can help
Consider it when a calculation is measurably expensive and its inputs often stay the same between renders. It can also help preserve a calculated object's identity when that value is passed to a memoized child component or used as a dependency by another Hook.
Potential candidates include filtering or sorting a large in-memory dataset, deriving a complex chart model, or transforming data that is expensive to process. The word “large” depends on the actual work and devices involved; measure your app instead of relying on a fixed item-count rule.
When useMemo is unnecessary
Avoid adding it reflexively to simple expressions:
const fullName = `${firstName} ${lastName}`;
For a calculation this small, useMemo usually adds complexity without a meaningful benefit. It also does not stop the component itself from rendering. It only lets React reuse the memoized value when the dependencies are unchanged.
If a component is slow because it renders too much DOM, performs expensive work elsewhere, or downloads too much JavaScript, useMemo may not address the real cause.
Common mistake: Missing dependencies
Every reactive value referenced by the calculation should appear in the dependency array:
const visibleItems = useMemo(() => {
return items.filter((item) => item.category === selectedCategory);
}, [items, selectedCategory]);
Leaving out selectedCategory can cause the cached result to be stale when the category changes. React's lint rules can help identify missing dependencies. Do not silence dependency warnings simply to make a memoization pattern work.
Common mistake: Depending on a new object each render
This pattern defeats memoization:
const options = { matchMode: "whole-word", query };
const results = useMemo(() => {
return searchItems(items, options);
}, [items, options]);
The options object is created again on every render, so its identity changes and the calculation runs again. Often the clearest fix is to create the object inside the memoized calculation and depend on its primitive inputs:
const results = useMemo(() => {
const options = { matchMode: "whole-word", query };
return searchItems(items, options);
}, [items, query]);
Do not add layers of memoization unless they solve a measured problem.
How to measure whether it helps
- Reproduce the interaction that feels slow.
- Use React DevTools Profiler to identify expensive renders.
- Measure the calculation with
console.timeandconsole.timeEndif appropriate. - Add
useMemoto a likely bottleneck. - Repeat the same interaction under similar conditions.
- Keep the change only if it improves performance or supports a real identity requirement without making the code harder to maintain.
Development Strict Mode can run calculations more than once to expose impure code. Make sure the calculation is pure and interpret development measurements carefully.
What about React Compiler?
React's documentation notes that React Compiler can automatically memoize values and functions in supported setups. If your project uses the compiler, follow the configuration and guidance for that version rather than assuming manual useMemo is always necessary. Existing projects without the compiler can still use useMemo when there is a clear reason.
Reference: https://react.dev/learn/react-compiler
Frequently asked questions
Does useMemo make every React app faster?
No. It can avoid repeating a costly calculation, but it has its own bookkeeping and does not fix every kind of performance problem. Measure before and after.
Is useMemo the same as useState?
No. useState stores a value that changes through state updates. useMemo caches a calculated value as a performance optimization; your code should still work correctly if React recalculates it.
Should I use useMemo for API calls?
No. Do not use useMemo to perform side effects or fetch data. Follow the data-fetching approach appropriate to your React or Next.js architecture.
Research and references
- React
useMemoAPI — https://react.dev/reference/react/useMemo - React Hooks overview — https://react.dev/reference/react/hooks
- React Compiler — https://react.dev/learn/react-compiler
For more ways to inspect rendering and scheduling, see the React 19.2 guide and its notes on Performance Tracks.
Try our QR Code Generator
Create clean, scannable QR codes for testing websites, URLs, and client handoffs.

Ukasha Altaf
Software Developer & Digital Tools Creator
Founder of Ukasha Mart. Building free, accessible browser-based utilities and writing in-depth tutorials on modern technology, freelancing, and practical online work.
Explore Further