DEV Community

Aman Kureshi
Aman Kureshi

Posted on

🧠 React.memo β€” Boost Performance by Preventing Unnecessary Renders

🧠 React.memo β€” Boost Performance by Preventing Unnecessary Renders

React.memo is a higher-order component that optimizes performance by skipping re-renders of a component if its props haven’t changed.

🎯 Why use React.memo?
β€’ Improves rendering speed
β€’ Saves CPU cycles
β€’ Useful for components that render the same UI most of the time

πŸ”§ Example:

import React from "react";
const Child = React.memo(function Child({ name }) {
console.log("Child rendered");
return <p>Hello, {name}</p>;
});

export default Child;

πŸ’‘ Usage:
<Child name="Aman" />
If the name prop doesn’t change, Child won’t re-render.

πŸ“Œ Key points:
β€’ Works only for functional components
β€’ Performs a shallow comparison of props
β€’ Combine with useCallback or useMemo for best results

React.memo is a simple yet powerful tool for optimizing React apps β€” but use it wisely, only where it’s needed.

Top comments (0)