An In-Depth Look at the Difference Between useMemo and useCallback

Senior developer explaining to a junior at a laptop

UseCallback is used to optimize the rendering behavior of your React function components, while useMemo is used to memoize expensive calculations to avoid having to recalculate them on every render. As a standard construction of hooks, those two solutions are not so different. Like with effect, a hook that manages the side-effects in functional components, argument callback comes first, and then an array of dependencies.

It’s more of a technical article with lots of details, so let’s cut to the chase!

As a standard construction of hooks, useMemo and useCallback are not so different:

  • useMemo memoizes expensive calculations to avoid redoing them on every render.
  • useCallback optimizes the rendering behavior of React function components by keeping callback references stable.

We’re sure that for many of you, this is enough to understand the difference. But let’s look deeper into the topic, though.

“Hooks?” Understanding React Hooks

What are React Hooks?

React Hooks are functions that allow you to use React features without writing a class. Hooks were first introduced in React 16.8.

These tools offer a more direct and functional approach to React’s fundamental concepts, such as:

  • state
  • lifecycle
  • context

They let you reuse stateful logic across components and simplify your code. You can eliminate the need for higher-order components and render props. 

Hooks provide a way to: 

  • handle side effects
  • manage state
  • utilize context

All this improves the modularity and readability of React apps.

Types of Hooks

Different React hook types serve different purposes:

  • useState lets you add state to functional components. It returns a stateful value and a function to update it.
  • useEffect lets you perform side effects in function components, such as fetching data. React remembers the function you passed and calls it after the DOM updates.
  • useContext lets you access context values directly within a functional component. This makes consuming context easier.

Other notable hooks across React 18 and React 19 include:

  • useReducer
  • useRef
  • useLayoutEffect
  • useImperativeHandle
  • useDebugValue
  • useId
  • useDeferredValue
  • useTransition
  • useInsertionEffect
  • useSyncExternalStore
  • useActionState (introduced in React 19 for form and action state)
  • useFormStatus (introduced in React 19 for reading parent form submission status)
  • useOptimistic (introduced in React 19 for optimistic UI updates)

These hooks serve more specialized purposes. They manage complex state logic, reference DOM elements, coordinate concurrent transitions, handle async actions, and customize the instance value exposed to parent components.

Introduction to useMemo vs useCallback in React

In complex React applications, performance optimization is critical. It helps maintain responsive user interfaces.

useMemo and useCallback are specifically designed to help with this by memoizing values and callbacks.

Let us explain their respective purposes in more detail:

  • useMemo. This hook makes sure the function is only recomputed when one of its dependencies changes. This is useful for expensive calculations or passing derived objects and arrays as props to child components. As a result of memoization, useMemo can significantly improve performance.

Here we have a code example:

jsx
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
  • useCallback. This hook memoizes callbacks. This process makes sure the same function reference is returned on every render unless its dependencies change. It is useful when passing callbacks as props to memoized child components to prevent them from re-rendering unnecessarily. useCallback maintains stable function references, reducing rendering overhead and improving the app’s performance.

We have a code example for it as well:

jsx
const memoizedCallback = useCallback(() => {
  doSomething(a, b);
}, [a, b]);

Used together and only where profiling shows a cost, useMemo and useCallback keep a large component tree responsive as the app grows.

Next Level: useMemo Syntax and Usage

To use useMemo in a React component, you provide it with these two things:

  • a calculation function that takes no arguments
  • a dependency array

The calculation will be re-executed only if one of the dependencies changes.

Here’s a code example of how you can use useMemo:

jsx
import React, { useMemo } from 'react';

const MyComponent = ({ a, b }) => {
  const memoizedValue = useMemo(() => {
    // Expensive calculation here
    return computeHeavyResult(a, b);
  }, [a, b]);

  return <div>{memoizedValue}</div>;
};

In this example, memoizedValue will only be recalculated when either a or b changes. This optimizes the component’s performance.

How?

It avoids unnecessary calculations on every render.

Next Level: React useCallback Syntax and Usage

To use useCallback in a React component, you provide it with these two things:

  • a callback function
  • a dependency array

The reference to the callback will change only if one of the dependencies changes.

Here’s a code snippet on how you can use useCallback:

jsx
import React, { useCallback } from 'react';

const MyComponent = ({ a, b }) => {
  const memoizedCallback = useCallback(() => {
    // Some action here
    console.log(a, b);
  }, [a, b]);

  return <Button onClick={memoizedCallback}>Click me</Button>;
};

In this example, the reference to memoizedCallback will only change when either the a or b value changes.

And how does this improve the app’s performance? The button component doesn’t re-render unnecessarily.

Recommended: How to Integrate a Third-Party API

ProCoders Compares useCallback vs useMemo

Similarities

  • Both useMemo and useCallback are used to optimize performance in React apps. They prevent unnecessary re-renders and recalculations. This makes the app run faster.
  • Both hooks use a dependencies array. They do it to determine when the memoized value or function should be updated. The array lists variables. When they change, it triggers the recomputation of the memoized value or function.

Differences

  • The primary difference between useMemo and useCallback is what they memoize.
    • useMemo memoizes values
    • useCallback memoizes functions
  • useMemo is suitable when you have expensive calculations or derived values. You may want to avoid recalculating them on every render. Examples include:
    • Calculating filtered lists
    • Complex mathematical computations
  • useCallback is a good choice when you need to pass stable callback references to child components. But we already covered that. The goal is to avoid unnecessary re-renders. Common use cases include:
    • Event handlers
    • Callback functions

Recommended: Advantages of Vue.js

Choosing Between useMemo and useCallback: Best Practices from ProCoders

Choosing between useMemo and useCallback isn’t just about knowing their definitions. It’s about understanding when and why to use them effectively. Here are some key considerations to help you decide.

Avoid Overusing Memoization with useMemo and useCallback

React is already fast for most components; unnecessary memoization makes code harder to read without a measurable gain. Before using useMemo or useCallback, consider whether the computation or function re-creation is actually slowing down your app.

Focus on Dependencies

Both hooks rely on dependency arrays. If dependencies change too often, memoization loses its effectiveness. Keep dependencies minimal to avoid unnecessary recalculations.

For example, a function depends on multiple variables, but only a few actually impact the result. Then, including extra dependencies forces React to recompute when it isn’t needed.

Be Mindful of Reference Equality

A common mistake with useCallback is passing it an unstable dependency, such as an object or array created on every render, which negates its purpose. React then sees a changed dependency, returns a new function and re-renders the child components.

To prevent this, keep unstable objects out of the dependency array or use React’s functional updates when working with setState.

Skip Memoizing Primitive Values

Using useMemo for simple values like numbers or strings is unnecessary. Memoization helps with computationally expensive operations, not basic assignments.

For instance, memoizing a single number doesn’t improve performance. It only adds complexity. Instead of useMemo(() => 5, []), just use const count = 5.

Consider the Memory Impact

Memoization stores values in memory, which can introduce overhead if overused. If recomputing a value is cheap, it’s better to let it recalculate rather than persist it unnecessarily.

If an operation takes well under a millisecond, memoization won’t provide noticeable gains. The best approach is to profile your application and optimize only when there’s measurable lag.

When to Skip Memoization

Memoization is not a requirement for every project. It is most useful when:

  • There is a measurable performance issue, such as expensive calculations or large re-renders.
  • A function is being passed as a prop to child components, causing unnecessary re-renders due to reference changes.
  • The computation being memoized actually benefits from avoiding re-execution.

If these conditions aren’t met, skipping memoization will keep your code cleaner and easier to maintain.

Choosing between useMemo and useCallback depends on whether you’re optimizing a value or a function. If you need to store a computed value efficiently, useMemo is the right choice. If you need to maintain a stable function reference to prevent unnecessary re-renders, useCallback is more appropriate. The key is knowing when the trade-off is worth it.

An In-Depth Example

useMemo calls your function during render and caches its return value, whereas useCallback caches the function itself so you or a child component can call it later. Specifically, useCallback(fn, deps) is equivalent to useMemo(() => fn, deps).

Here is an example:

jsx
function memoUsed() {
  const value = useMemo(() => {
    return 'insert JSX here';
  }, []);

  return value;
}

function callbackUsed() {
  const getValue = useCallback(() => {
    return 'insert JSX here';
  }, []);

  return getValue();
}

As you can see, useMemo stores the evaluated result of the function, whereas useCallback stores the function without executing it until getValue() is invoked.

When to Use useMemo in React

Expensive Calculations: If you have a component that performs heavy calculations, you can use useMemo.

jsx
const expensiveCalculation = (num) => {
  // Some expensive calculation
  return num * 2;
};

const MyComponent = ({ num }) => {
  const memoizedValue = useMemo(() => expensiveCalculation(num), [num]);

  return <div>{memoizedValue}</div>;
};

Referential Equality for Dependency Arrays: When passing derived objects or filtered arrays as dependencies to other hooks (like useEffect or useCallback), useMemo preserves referential equality across renders when the underlying input has not changed.

jsx
const MyComponent = ({ items }) => {
  const activeItems = useMemo(
    () => items.filter((item) => item.isActive),
    [items]
  );

  useEffect(() => {
    // This effect runs only when activeItems is recomputed
  }, [activeItems]);

  return <div>{activeItems.length}</div>;
};

Optimizing Render Performance: When you have a list or table that gets re-rendered frequently due to parent component updates, useMemo avoids recomputing derived list data on every parent render, and React.memo on the child avoids re-rendering it when props are unchanged.

jsx
const MyComponent = ({ data }) => {
  const sortedData = useMemo(
    () => [...data].sort((a, b) => a.name.localeCompare(b.name)),
    [data]
  );

  return (
    <ul>
      {sortedData.map((item) => (
        <li key={item.id}>{item.name}</li>
      ))}
    </ul>
  );
};

When to Use useCallback in React

Event Handlers: When passing event handlers to memoized child components, useCallback ensures the child receives the same function instance across renders.

jsx
const MyComponent = () => {
  const handleClick = useCallback(() => {
    console.log('Button clicked');
  }, []);

  return <Button onClick={handleClick}>Click Me</Button>;
};

Dependencies in useEffect: When a function is called inside a useEffect and needs to be listed in its dependency array, useCallback keeps the function reference stable unless userId changes.

jsx
const MyComponent = ({ userId }) => {
  const fetchData = useCallback(() => {
    // Fetch data for the user
  }, [userId]);

  useEffect(() => {
    fetchData();
  }, [fetchData]);

  return <div>Data fetched</div>;
};

Performance Optimization in Memoized Components: When using React.memo to prevent unnecessary re-renders of child components, useCallback ensures that callback props passed to the child do not change unless necessary.

jsx
const MyButton = React.memo(({ onClick }) => (
  <button onClick={onClick}>Click Me</button>
));

const MyComponent = () => {
  const handleClick = useCallback(() => {
    console.log('Button clicked');
  }, []);

  return <MyButton onClick={handleClick} />;
};

useMemo and useCallback in 2026: what React Compiler changes

React Compiler 1.0 reached a stable release on October 7, 2025 (React team announcement). It analyzes components and hooks at build time and inserts memoization automatically, working natively with React 19 and supporting React 17 and 18 via react-compiler-runtime. Major frameworks including Next.js, Vite, and Expo ship first-party support, and compiler-powered rules are built directly into eslint-plugin-react-hooks.

Because of that, the React team recommends relying on the compiler for default memoization in new code and keeping useMemo and useCallback as explicit escape hatches where you need precise control over referential identity. The main case is a memoized value or function used as an effect dependency or passed across an external library boundary, where you want the effect not to fire again when nothing meaningful changed. In existing code, the React Compiler docs advise leaving current manual memoization in place unless you test the removal, because removing useMemo or useCallback can alter compilation output.

In practice, review memoization the same way whether a person or an AI assistant wrote it. Ask what render cost it removes, and check it in React DevTools Profiler. Wrappers added by default, without a measurement, are noise.

If you are deciding who should own this kind of performance work on your React codebase, see our React.js developers page, or the React outsourcing guide.

Check React.js developers availability

FAQ
01What is the difference between useMemo and React useMemo?

There is no difference. React.useMemo is the full reference when explicitly importing the hook from React, while useMemo is the shorthand commonly used in code. Both function the same way.

02What is useCallback in React used for?

useCallback memoizes a function, ensuring it keeps the same reference across renders unless dependencies change. This prevents unnecessary re-renders, especially when passing functions as props to child components.

03When to use useMemo vs useCallback?

Use useMemo to store the result of a computation and avoid recalculating it on every render. Use useCallback to store a function reference so it doesn’t change unnecessarily. If optimizing a computed value, use useMemo. If preventing unnecessary function re-creations, use useCallback.

04What are the advantages and disadvantages of useCallback and useMemo?

Advantages include better performance by reducing unnecessary re-renders, efficient memory use, and improved component rendering. Disadvantages include added complexity, potential overuse, and minimal impact if applied where optimization isn’t needed.

05Does useCallback work without React memo?

Yes, useCallback works on its own, but its main benefit is when combined with React.memo. This prevents child components from re-rendering due to function reference changes.

06Do I still need useMemo and useCallback with React Compiler?

Less often. React Compiler 1.0 memoizes automatically, and the React team recommends relying on it in new code. Keep useMemo and useCallback where you need control, for example a value used as an effect dependency. In existing code, leave current memoization in place unless you test the removal.

07How do React useMemo and useCallback improve performance in React applications?

They optimize performance by preventing unnecessary calculations and function re-creations. useMemo ensures computations run only when dependencies change. useCallback ensures functions retain the same reference, avoiding unnecessary re-renders in child components.

08When should you use useMemo in a React component?

Use useMemo when a component performs expensive calculations that don’t need to run on every render. This is useful for filtering large datasets, formatting values, or processing computationally heavy operations that should only update when relevant dependencies change.

09When should you use useCallback in a React component?

Use useCallback when a function is passed as a prop to a child component or used in a dependency array. This prevents React from treating it as a new function on every render, reducing unnecessary updates.

10What are the common use cases for useMemo?

Common use cases include optimizing performance when dealing with large lists, preventing redundant calculations in rendering-heavy components, and maintaining stable references in dependency arrays for other hooks like useEffect.

11What are the common use cases for useCallback?

Use useCallback when passing event handlers or functions as props to child components, preventing them from triggering unnecessary re-renders. It’s also useful for ensuring stable function references inside hooks like useEffect to prevent unintended side effects.

12Can useMemo and useCallback be used together in a single component?

Yes, they can work together. useMemo handles computed values, while useCallback keeps function references stable. Using both in performance-sensitive components helps reduce unnecessary re-renders and optimizes rendering efficiency.

13How to debug performance issues with useMemo and useCallback?

Use the React DevTools Profiler to inspect re-renders and check if memoization is working as expected. Identify unnecessary re-renders and review dependency arrays to ensure they only include values that affect the output. If a component still re-renders excessively, verify if memoization is actually needed.

14How to reduce re-renders in React with useMemo and useCallback?

Memoize values with useMemo and functions with useCallback to maintain stable references and prevent React from treating them as new instances on every render. Use React.memo for child components receiving props to further optimize rendering.

15How to improve React component performance with useMemo and useCallback?

Use useMemo for computations that should not re-run unnecessarily and useCallback to prevent function re-creations that trigger re-renders. Optimize dependency arrays to avoid stale values and apply memoization only when profiling reveals performance issues.

Conclusion

useMemo memoizes the result of an expensive calculation. useCallback keeps a function reference stable between renders. Both take a dependency array, and both pay off only when the saved work is larger than the cost of memoizing.

Start without them, profile, and add them where the Profiler shows wasted renders. Keep dependencies minimal, and do not memoize trivial values such as a constant number. With React Compiler in your build, you will write fewer of these by hand, but the reasoning above still decides the cases you do keep.

You can read more on React optimizations in our blog.

If you need senior React engineers to review or speed up your app, ProCoders sends a shortlist within 72 hours, and engineers typically start in about 14 days. See our React.js developers or talk to us about a dedicated development team.