How does React.memo improve performance?
React.memo is a higher-order component that memoizes functional components. It only
re-renders the component if its props have changed.
- Before: Every re-render, even if props haven’t changed.
- After: Prevents unnecessary re-renders when props remain the same.
const MyComponent = React.memo(function MyComponent({ name }) {
return <div>{name}</div>;
});
// MyComponent will only re-render if the `name` prop changes