Introduction
As your React application grows, you may notice it slowing down or lagging, especially when components re-render more often than necessary. React re-renders components whenever their state or props change — but sometimes, unnecessary re-renders can hurt performance. This is where memo, useMemo, and useCallback come in. These tools help you control re-renders, avoid heavy calculations on each render, and prevent functions from being recreated unnecessarily.
Why Do React Apps Become Slow?
React becomes slow when components re-render too many times. This usually happens because:
Props or state change frequently
Functions are recreated on every render.
Heavy calculations run repeatedly.
Large lists render without optimization.
Child components re-render even when data has not changed
Using memo, useMemo, and useCallback helps fix these issues and makes your app run more smoothly.
1. React.memo — Prevents Unnecessary Re-renders of Components
React.memo is used to stop a component from re-rendering if its props haven’t changed.
How It Works
React normally re-renders child components whenever the parent renders. But with memo, React compares old and new props — if they are the same, it skips the render.
Example Without memo
function Child({ count }) {
console.log("Child rendered");
return <h2>Count: {count}</h2>;
}
function App() {
const [value, setValue] = useState(0);
return (
<>
<button onClick={() => setValue(value + 1)}>Increase</button>
<Child count={10} />
</>
);
}
Here, Child re-renders every time App re-renders, even though count never changes.
Fix Using memo
const Child = React.memo(function Child({ count }) {
console.log("Child rendered");
return <h2>Count: {count}</h2>;
});
Now Child renders only once, unless its props change.
When to Use memo
When child components receive the same props repeatedly
When rendering large UI blocks
When components re-render without any real change
When Not to Use memo
When props always change
On very small components (overhead may slow things instead of improving)
2. useMemo — Caches Expensive Calculations
useMemo is used when you have a slow or heavy calculation that you do not want to repeat on every render.
How It Works
useMemo remembers the result of a function and recalculates it only when dependencies change.
Example Without useMemo
function App() {
const [count, setCount] = useState(0);
const heavyResult = slowCalculation(count);
return (
<>
<h2>Result: {heavyResult}</h2>
<button onClick={() => setCount(count + 1)}>Increase</button>
</>
);
}

Join the conversation! Your thoughts help the community grow.