Course contentsShow
← React
Lesson 906 of 2,39623. useMemo and useCallbackFree lesson

When Simple Values Don't Need useMemo

Recognizing that primitive calculations and basic array/object literals are cheaper than memoization checks.

When Simple Values Don't Need useMemo

What you'll learn: Why wrapping trivial calculations in useMemo actually makes your code slower, not faster.

The Core Idea

Not every value needs memoization. In fact, useMemo has its own cost: React must check the dependency array, compare each dependency, and manage the memoized cache. For simple, cheap operations, this overhead is more expensive than just recalculating the value on every render.

Think of it like this: If you need to add 2 + 2, would you write it down in a notebook, check the notebook every time, and update it only when the numbers change? No—you'd just add them in your head each time. The notebook overhead isn't worth it for such a simple task.

What Counts as "Simple"?

  • Primitive calculations: const doubled = count * 2
  • String concatenation: const greeting = "Hello, " + name
  • Boolean logic: const isValid = age >= 18 && hasPermission
  • Simple object/array literals: const style = { color: 'blue' } (when referential identity doesn't matter)

These operations take nanoseconds. The useMemo dependency check takes longer than the calculation itself.

The Anti-Pattern

// ❌ Unnecessary memoization
const doubled = useMemo(() => count * 2, [count]);

// ✅ Just compute it
const doubled = count * 2;

Reserve useMemo for genuinely expensive operations—complex array transformations, heavy filtering, recursive calculations—or when you specifically need referential stability for a downstream optimization.

Key Takeaway: Don't memoize primitive calculations or cheap operations. The memoization overhead costs more than recalculating simple values. Optimize only what profiling shows is actually slow.