useMemo vs useCallback in React: Difference and Trade Off
Explore useMemo vs useCallback in React with examples. Learn the key differences between useMemo and useCallback, use cases, and when to choose one over the other in React applications.
Anuj Sharma
Last Updated Jun 19, 2026

useMemo and useCallback are two important hooks in React that help optimize performance by memoizing values and functions, respectively. While they may seem similar, they serve different purposes based on the data they handle.
In this blog, we delve into finding out the key differences between useMemo vs useCallback hook in react,
Table of Content
Understanding useMemo Hook
useMemo is used to memoize values or computations and recompute them only when one of the dependencies has changed. It is helpful when you need to calculate a value that is computationally expensive and should not be recalculated on every render.
For example, consider a scenario where you want to calculate a factorial of a number:
const factorial = useMemo(() => {
return calculateFactorial(number);
}, [number]);
- It takes a function that computes the value as the first argument.
- The second argument is an array of dependencies. The value will only be recomputed when these dependencies change.
Understanding useCallback Hook
useCallback is used to memoize functions, primarily for optimizing performance in child components that rely on reference equality. It returns a memoized version of the callback function that only changes if one of the dependencies has changed.
For example, in a scenario where you have a handler function for a button click:
const handleClick = useCallback(() => {
console.log('Button clicked!');
}, []);
- It takes a callback function as the first argument.
- The second argument is an array of dependencies. The callback will only be recreated if any of these dependencies change.
useMemo vs useCallback: What is the Difference
| Area | useMemo | useCallback |
|---|---|---|
| Usage | Used to memoize a value | Used to memoize a function |
| Dependencies | Depends on an array of dependencies | Depends on an array of dependencies |
| Return | Returns a memoized value | Returns a memoized callback function |
Key Differences
- useMemo: Memoizes a value and returns it. It helps in avoiding expensive calculations on every re-render.
- useCallback: Memoizes a function and returns it. Useful when passing callbacks to child components to prevent unnecessary re-renders.
Code Example
import React, { useMemo, useCallback, useState } from 'react';
const Component = () => {
const [count, setCount] = useState(0);
// Memoize value
const memoizedValue = useMemo(() => {
return count * 2;
}, [count]);
// Memoize Function
const memoizedCallback = useCallback(() => {
setCount(count + 1);
}, [count]);
return (
div>
p>Memoized Value: {memoizedValue}/p>
button onClick={memoizedCallback}>Increment/button>
/div>
);
};
export default Component;
Use Cases
- useMemo: When you have a computationally expensive operation that depends on specific values and you want to avoid recalculating that value on every render.
- useCallback: When passing callbacks to child components, and you want to prevent unnecessary re-renders by memoizing the function.
Understand When to Choose One Over the Other
Choose useMemo when you need to memoize a value that depends on specific dependencies to avoid unnecessary recalculations. Use useCallback when you need to memoize a function, especially when passing it as a prop to child components, to prevent them from re-rendering on parent component updates.
Understanding the differences and use cases of useMemo and useCallback can significantly improve the performance and maintainability of your React applications.
Further Reading
A seasoned Sr. Engineering Manager at GoDaddy (Ex-Dell) with over 12+ years of experience in the frontend technologies. A frontend tech enthusiast passionate building SaaS application to solve problem. Know more about me 🚀
Learn Next
Featured
100+ Top React JS Interview Questions And Answers
Comments
Be the first to share your thoughts!
No comments yet.
Start the conversation!
Share your expertise
Publish a blog or quick notes on topics you know well — your write-up could be the answer someone needs before their next frontend interview.
Build your portfolio
Help the community
Sharpen your skills
Earn goodies
Other Related Blogs
useRef vs useState in React: Difference & Trade-off
Anuj Sharma
Last Updated Jun 19, 2026
Explore useRef vs useState in React with examples. Learn the key differences between useRef and useState, use cases, advantages, and disadvantages, and when to choose one over the other in React applications.
useRef vs createRef in React: Difference and Trade Off
Anuj Sharma
Last Updated Jun 19, 2026
Explore useRef vs createRef in React with examples. Learn the key differences between useRef and createRef, use cases and when to choose one over the other in React applications
useState vs useReducer in React: Understand the Difference & Trade-Off
Anuj Sharma
Last Updated Jun 19, 2026
Explore useState vs useReducer in React with examples. Learn key differences, use cases, advantages, disadvantages, and when to choose one over the other in React applications and interviews.
React.memo vs useMemo in React: Difference & Trade Off
Anuj Sharma
Last Updated Jun 19, 2026
Explore React.memo vs useMemo in React with examples. Learn key differences between React.memo and useMemo, use cases and when to choose one over the other in React applications.
useEffect vs useLayoutEffect in React: Understand the Difference & Trade-Off
Anuj Sharma
Last Updated Jun 17, 2026
Explore useEffect vs useLayoutEffect in React with examples. Learn key differences, use cases, advantages, disadvantages, and when to choose one over the other in React applications and interviews.
React Hook Rules: Why hooks declarations are not allowed inside functions
Frontendgeek
Last Updated Feb 6, 2026
A quick guide to explain an important react interview question, why React Hooks declarations are not allowed inside functions or any conditional blocks with code example.
Implement usePrevious Hook in React [Interview]
Anuj Sharma
Last Updated Dec 23, 2025
Understand the implementation and usage of usePrevious Hook in React to help tracking previous value in react app.
20 Most Asked Custom Hooks In React for Interviews
Anuj Sharma
Last Updated Jun 11, 2026
Explore the Most Common Custom Hooks in React asked in the React Interviews. It includes the code example of all the custom hooks in react for a quick revision before interview.
