October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Stop Unnecessary React Renders with memo, useMemo, and useCallback

Profile sluggish interactions, then use memo, useMemo, or useCallback only when stable props, costly calculations, or callback identity make a measurable difference.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To reduce avoidable React work, first profile the interaction that feels slow, then apply the smallest effective optimization: memo can let a component skip a render when its props are unchanged, useMemo can cache a calculation, and useCallback can keep a function prop stable. These tools are performance optimizations, not correctness fixes or guarantees. If React Compiler is enabled, it may handle much of this memoization automatically.

What each optimization prevents

Tool What it can avoid When it is useful
memo Rendering a component when its props have not changed A component is costly to render and often receives the same props
useMemo Repeating a calculation while its dependencies are unchanged A calculation is measurably expensive, or a derived object or array needs a stable identity for a memoized child
useCallback Passing a newly created function identity to a memoized child or another dependency-sensitive consumer A callback’s identity matters to a consumer and its dependencies are stable

React compares props and hook dependencies using Object.is. For objects, arrays, and functions, that means identity matters: creating a new object with the same contents does not make it the same value.

As an Amazon Associate I earn from qualifying purchases.

How a parent render can reach a child

When a parent renders, it may create a fresh array, object, or callback and pass it to a child wrapped in memo. The child sees that prop as changed, even if its contents or behavior seem equivalent, and may render again. Stabilizing the relevant value with useMemo or callback with useCallback gives memo a chance to skip the child render, provided its other props are unchanged too.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, a filtered list can be calculated only when its inputs change, while a row component can skip rendering if its item and callback props remain stable:

import { memo, useCallback, useMemo, useState } from 'react';

const TodoRow = memo(function TodoRow({ todo, onToggle }) {
  return (
    <button onClick={() => onToggle(todo.id)}>
      {todo.done ? '✓' : '○'} {todo.text}
    </button>
  );
});

function TodoList({ todos }) {
  const [showDone, setShowDone] = useState(false);

  const visibleTodos = useMemo(
    () => todos.filter(todo => showDone || !todo.done),
    [todos, showDone]
  );

  const handleToggle = useCallback((id) => {
    // Update the relevant todo in the owning state.
  }, []);

  return visibleTodos.map(todo => (
    <TodoRow key={todo.id} todo={todo} onToggle={handleToggle} />
  ));
}

The update logic is intentionally omitted: the example illustrates identity and dependencies, not a complete state-management implementation. In a real component, include every reactive value referenced by a calculation or callback in its dependency list. Do not omit dependencies to force a cached value; that can leave a closure using stale data.

Using memo for a component

memo(Component) returns a component React can usually skip rendering when its props compare equal. By default, React compares each prop with Object.is. You can supply a custom comparison function, but it must correctly account for every prop that affects output or behavior; an incorrect comparison can preserve stale UI or callbacks. Start with the default comparison unless profiling shows a need for something more specialized.

A memoized component can still render when its own state changes or when context it uses changes. Memoization only addresses parent-driven renders whose props are unchanged; it does not freeze the component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using useMemo for calculations and stable values

useMemo(() => calculate(input), [input]) caches the calculation result until a dependency changes. This is most useful when the calculation itself is expensive, or when the resulting object or array is passed to a memoized component and would otherwise get a new identity on each parent render.

Keep the calculation pure: it should derive a value from its inputs rather than cause side effects. If the work is cheap and the result is not used in a way that depends on stable identity, caching it can make the code harder to understand without improving the interaction. React’s documentation says to rely on useMemo only as a performance optimization: React useMemo reference.

Using useCallback for function props

useCallback(fn, [dependencies]) caches a function definition between renders while its dependencies remain unchanged. It does not prevent JavaScript from evaluating the function expression during rendering; React returns the cached function when appropriate. Its value is that a consumer such as a memoized child can receive a stable callback identity.

Include every reactive value used by the callback in the dependency list. If those values change, React returns a new callback, and a memoized child receiving it may render. Avoid adding useCallback to every handler by habit: if no consumer benefits from a stable identity, the extra dependency maintenance may be needless.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When memoization is not the right fix

React recommends not adding memoization by default. Before doing so, confirm the cause of the slow interaction and consider simpler changes:

  • Keep rendering pure so the same inputs produce the same output.
  • Keep state close to the components that use it instead of lifting it unnecessarily high in the tree.
  • Look for Effects that set state and trigger an avoidable extra render; remove unnecessary Effects where possible.
  • Check whether a prop is always a newly created object, array, or callback, and whether stabilizing it would actually let a costly child skip work.
  • For an Effect dependency, consider moving an object or function inside the Effect, or defining it outside the component, rather than memoizing it solely to keep the dependency stable.

Do not use memoization to hide incorrect behavior. Fix the underlying logic first; a cached result or callback must not be relied on to make an impure or incorrectly specified component work.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to decide: profile, then optimize

  1. Reproduce the specific interaction that feels sluggish rather than optimizing based on render counts alone.
  2. Use the React Developer Tools Profiler to identify which components render and where time is spent.
  3. Check for unnecessary Effects, state placed too high in the component tree, expensive calculations, and props whose identities change on each render.
  4. Apply the narrowest relevant optimization: memo for a costly child with stable props, useMemo for a costly calculation or necessary stable value, or useCallback when callback identity affects a consumer.
  5. Profile the same interaction again. Keep the change only if it improves the observed problem and remains understandable.

What React Compiler changes

React Compiler can automatically memoize components, values, and functions, reducing the need to add memo, useMemo, and useCallback manually. React’s current guidance recommends relying on the compiler for new code when it is enabled; manual memoization remains available when precise control is needed. Check whether the compiler is configured in your project before adding optimization wrappers by default. See the official React Compiler introduction and React Compiler guide.

For API details, consult React’s references for memo, useMemo, and useCallback.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.