🌐
React
react.dev › reference › react › useMemo
useMemo – React
On every subsequent render, React will compare the dependencies with the dependencies you passed during the last render. If none of the dependencies have changed (compared with Object.is), useMemo will return the value you already calculated before.
🌐
W3Schools
w3schools.com › react › react_usememo.asp
React useMemo Hook
The React useMemo Hook returns a memoized value.
Discussions

reactjs - What's the difference between useCallback and useMemo in practice? - Stack Overflow
Maybe I misunderstood something, but useCallback Hook runs everytime when re-render happens. I passed inputs - as a second argument to useCallback - non-ever-changeable constants - but returned me... More on stackoverflow.com
🌐 stackoverflow.com
When to use or not use useMemo and useCallback?
I've found the easiest way to think about memoization is that every React component is just a function. If you define a variable within a function, every time that function gets called, the variable gets redefined. This is the same for React components - every time a component re-renders, the variables you define within that component get redefined. Often this isn't a problem, however if you're passing those variables down as props to child components, it means those child components get re-rendered too every time the variables change, because this is just how React works, and this is where memoization comes in. When you memoize a value (useMemo/useCallback) it means that value won't get redefined unless the values in its dependency array change. So because they don't get redefined, the components you pass those values to as props don't re-render because the props don't change. If you're only building a small app, sometimes you can get away with not memoizing anything, and in most cases I'd suggest not memoizing anything unless you run into performance problems. If you do though, there's a good chance the reason behind the performance problems is components rendering more times than they need to, which is where memoizing values can help. More on reddit.com
🌐 r/reactjs
38
71
February 27, 2023
How often to use useCallback/useMemo?
I believed that the “performance cost” of useMemo was a thing. But there are multiple articles out there (sorry, I’m in mobile right now - can’t link) that state this is not a thing, including profiling results and all. And like you stated, React Forget is is essentially going to do the same. The only reason to not put useMemo on virtually everything is legibility and complexity. And that’s a case by case consideration. I personally hate reading through a series of useMemos because it causes so much cognitive overhead for such a simple piece of code (a bunch of variables). More on reddit.com
🌐 r/reactjs
55
36
November 19, 2023
What is the purpose of useMemo-ing a whole component? A lack of trust of react change detection? Explicitly stating when the component should re-render?
The other answers saying "it's useless or a mistake" are unfortunately wrong. This is actually valuable for a little-known React performance optimization. If you return the exact same element reference as the last render, React will skip rendering that child. It's the same concept as wrapping a component in React.memo(), except it's controlled by the parent: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#component-render-optimization-techniques As an example, this is how React-Redux's connect API implements avoiding renders of the child component if the props values haven't changed: https://github.com/reduxjs/react-redux/blob/v9.1.0/src/components/connect.tsx#L752-L779 More on reddit.com
🌐 r/reactjs
32
62
February 12, 2024
🌐
Medium
medium.com › @amanrags › when-to-use-to-usememo-in-react-8814910195d6
When to use to useMemo in React?. Here is an explanation of optimizing… | by amandeep kumar | Medium
February 16, 2024 - Memoized Value Propagation: Use useMemo when the calculated value is further used as a dependency for other calculations or hooks (e.g., another useMemo or useEffect).
🌐
React
react.dev › reference › eslint-plugin-react-hooks › lints › use-memo
use-memo – React
useMemo is for computing and caching expensive values, not for side effects.
🌐
LogRocket
blog.logrocket.com › home › react usememo vs. usecallback: a pragmatic guide
React useMemo vs. useCallback: A pragmatic guide - LogRocket Blog
March 6, 2025 - The useMemo Hook serves a similar purpose as useCallback, but it returns a memoized value instead of a function reference. This allows you to avoid repeatedly performing potentially costly operations until necessary.
🌐
LogRocket
blog.logrocket.com › home › react.memo vs. usememo: major differences and use cases
React.memo vs. useMemo: Major differences and use cases - LogRocket Blog
June 4, 2024 - Imagine having a component displaying thousands of data, and each time the user clicks a button, every piece of data in that component or tree re-renders when they don’t need to. This is where React.memo() or useMemo() becomes necessary to give us performance optimizations.
🌐
Toontown Combos
zzzachzzz.github.io › blog › react-hooks-how-to-use-usememo
React Hooks: How to Use useMemo
March 5, 2021 - useMemo is a hook used to memoize values inside a React component. It's a performance optimization to avoid recalculating expensive values on every render.
Find elsewhere
🌐
Developerway
developerway.com › posts › how-to-use-memo-use-callback
How to useMemo and useCallback: you can remove most of them
The most important thing to remember here is that both useMemo and useCallback are useful only during the re-renders phase. During the initial render, they are not only useless but even harmful: they make React do some additional work. This means that your app will become slightly slower during the initial render.
🌐
DigitalOcean
digitalocean.com › community › tutorials › react-usememo
Understanding the React useMemo Hook | DigitalOcean
October 9, 2020 - The dependencies act similar to arguments in a function. The dependency’s list are the elements useMemo watches: if there are no changes, the function result will stay the same. Otherwise, it will re-run the function. If they don’t change, it doesn’t matter if our entire component re-renders, the function won’t re-run but instead return the stored result.
🌐
Medium
medium.com › @abhikshirsagar1999 › understanding-usememo-in-react-a-complete-guide-86c086bf3f27
Understanding useMemo in React: A Complete Guide | by Abhi Kshirsagar | Medium
November 25, 2024 - `useMemo` is a React hook introduced in React 16.8. It allows you to memoize a computed value so that it’s recalculated only when its dependencies change.
🌐
DEV Community
dev.to › kells › react-memo-vs-usememo-3j52
React Memo vs useMemo - DEV Community
March 11, 2024 - By default, React re-renders child components when the parent component re-renders. If there is no lag or nothing slowing your app down, then it's fine. However, if there is, consider wrapping the data mutation or heavy calculation in your component with useMemo.
🌐
Furkan's Notes
blog.furkanozbek.com › react-hooks-usememo
React Hooks: useMemo
September 5, 2021 - useMemo hook will run the expensive operation when one of the dependencies has been changed.
🌐
Mimo
mimo.org › glossary › react › usememo-hook
React useMemo Hook: Syntax, Usage, and Examples
React's useMemo hook helps you optimize the performance of your components by memoizing the result of expensive computations. Instead of recalculating a value on every render, useMemo ensures that the computation only runs again when one of its dependencies changes.
🌐
Josh W. Comeau
joshwcomeau.com › react › usememo-and-usecallback
Understanding useMemo and useCallback • Josh W. Comeau
In this case, we're essentially saying “recalculate the list of primes only when selectedNum changes”. When the component re-renders for other reasons (eg. the time state variable changing), useMemo ignores the function and passes along the cached value.
🌐
Medium
eihsan94.medium.com › did-you-get-the-memo-how-to-use-react-usememo-eb67092e3871
Did you get the memo? How to Use react useMemo? | by Ihsan Engku | Medium
January 4, 2024 - Ok, now we’re getting somewhere. So basically, useMemo is used for improving the performance of a React app during re-render by storing the calculated values in the component's memory.
Top answer
1 of 8
383

TL;DR;

  • useMemo is to memoize a calculation result between a function's calls and between renders
  • useCallback is to memoize a callback itself (referential equality) between renders
  • useRef is to keep data between renders (updating does not fire re-rendering)
  • useState is to keep data between renders (updating will fire re-rendering)

Long version:

useMemo focuses on avoiding heavy calculation.

useCallback focuses on a different thing: it fixes performance issues when inline event handlers like onClick={() => { doSomething(...); } cause PureComponent child re-rendering (because function expressions there are referentially different each time)

This said, useCallback is closer to useRef, rather than a way to memoize a calculation result.

Looking into the docs I do agree it looks confusing there.

useCallback will return a memoized version of the callback that only changes if one of the inputs has changed. This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders (e.g. shouldComponentUpdate).

Example

Suppose we have a PureComponent-based child <Pure /> that would re-render only once its props are changed.

This code re-renders the child each time the parent is re-rendered — because the inline function is referentially different each time:

function Parent({ ... }) {
  const [a, setA] = useState(0);
  ... 
  return (
    ...
    <Pure onChange={() => { doSomething(a); }} />
  );
}

We can handle that with the help of useCallback:

function Parent({ ... }) {
  const [a, setA] = useState(0);
  const onPureChange = useCallback(() => {doSomething(a);}, []);
  ... 
  return (
    ...
    <Pure onChange={onPureChange} />
  );
}

But once a is changed we find that the onPureChange handler function we created — and React remembered for us — still points to the old a value! We've got a bug instead of a performance issue! This is because onPureChange uses a closure to access the a variable, which was captured when onPureChange was declared. To fix this we need to let React know where to drop onPureChange and re-create/remember (memoize) a new version that points to the correct data. We do so by adding a as a dependency in the second argument to `useCallback :

const [a, setA] = useState(0);
const onPureChange = useCallback(() => {doSomething(a);}, [a]);

Now, if a is changed, React re-renders the <Parent>. And during re-render, it sees that the dependency for onPureChange is different, and there is a need to re-create/memoize a new version of the callback. This is passed to <Pure> and since it's referentially different, <Pure> is re-rendered too. Finally everything works!

NB not just for PureComponent/React.memo, referential equality may be critical when use something as a dependency in useEffect.

2 of 8
140

useMemo and useCallback use memoization.

I like to think of memoization as remembering something.

While both useMemo and useCallback remember something between renders until the dependancies change, the difference is just what they remember.

useMemo will remember the returned value from your function.

useCallback will remember your actual function.

Source: What is the difference between useMemo and useCallback?

🌐
Medium
austinrt.medium.com › demystifying-react-hooks-usememo-1219661d0af0
Demystifying React Hooks — useMemo | by austin | Medium
February 16, 2023 - If you’re here solely to understand ... React Docs, much like useCallback, useMemo is an opt-in performance enhancer Hook used to create referential equality for function results....
🌐
Refine
refine.dev › home › blog › tutorials › react usememo hook guide with examples
React useMemo Hook Guide with Examples | Refine
September 19, 2024 - React useMemo() hook is a function that caches the value produced from an expensive function used inside a React component. It accepts the expensive function and works by storing the value produced from the function when that is passed the same ...
🌐
Telerik
telerik.com › blogs › learn-how-usememo-hook-once-all
Learn How to Use the useMemo Hook Once and for All
February 5, 2024 - The useMemo hook is built into React, allowing you to memoize a value. In other words, useMemo caches the result of a function and returns the cached value whenever it’s called again with the same arguments.
🌐
Devhandbook
devhandbook.com › react › hooks › usememo
How to useMemo in React | Dev Handbook
While useMemo is used to memoize values, React.memo is used to wrap React components to prevent re-renderings.