Skip to main content
InterviewHubPRO
Section Overview
Q48

Question 48 of 407

General

12%
React Core & Hooks (407 Qs)•General

How do you memoize a component?

mid LevelCode ExampleComponents

In React, you can memoize a functional component using React.memo(). It wraps your component to prevent unnecessary re-renders if its props have not changed (via shallow comparison):

jsx
import React from 'react';

const UserProfile = React.memo(function UserProfile({ name, role }) {
  return <div>{name} ({role})</div>;
});

export default UserProfile;

For class components, you can extend React.PureComponent which automatically implements shouldComponentUpdate() with a shallow prop and state comparison.