MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Memoizing Components with React memo0%
Study Materials
React.js for IntermediateProgress 0%
1.1Component Reusability and Polymorphic Components1.2Render Props Pattern in Modern React1.3Higher-Order Components vs Modern Hooks1.4Compound Components Pattern Explained
8.1React Re-render Rules and Profiling Bottlenecks8.2Memoizing Components with React memo8.3The useCallback Hook and Stabilizing Callback Props8.4The useMemo Hook and Expensive Computations
HomeTutorialsReact.js for IntermediateMemoizing Components with React memo
The useCallback Hook and Stabilizing Callback Props

Memoizing Components with React memo

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. What is React.memo?

By default, when a parent component re-renders, all of its children re-render. If a child component is computationally heavy or renders a large list, re-rendering it unnecessarily when its props have not changed wastes CPU cycles.

React.memo is a Higher-Order Component that memoizes a functional component.

When a component is wrapped in React.memo, React skips rendering the component if its props have not changed since the last render.

$$\text{Next Props} \stackrel{\text{shallow equal}}{===} \text{Prev Props} \implies \text{Skip Render (Reuse Cached VDOM)}$$

2. Basic Usage of React.memo

1import React, { memo } from 'react';
2 
3// Wrap functional component in memo()
4const CourseSummaryCard = memo(function CourseSummaryCard({ title, duration, rating }) {
5 console.log(`Rendering CourseSummaryCard: ${title}`);
6 
7 return (
8 <div className="summary-card">
9 <h3>{title}</h3>
10 <p>Duration: {duration} | Rating: ★ {rating}</p>
11 </div>
12 );
13});
14 
15export default CourseSummaryCard;

If the parent component re-renders (due to an unrelated state change like a clock ticker), CourseSummaryCard will skip rendering entirely, reusing its previous Virtual DOM result.

3. The Shallow Comparison Trap

By default, React.memo compares props using shallow equality (Object.is):

  • Primitives (strings, numbers, booleans) are compared by value ('React' === 'React' -> true).
  • Complex types (objects, arrays, functions) are compared by memory reference ({} === {} -> false)!

If a parent passes an unmemoized inline object or function to a memoized child, React.memo will completely fail to stop re-renders!

1// ❌ FAILS: Passes new object and new function references on EVERY render!
2<CourseSummaryCard
3 title="React Mastery"
4 settings={{ theme: 'dark' }} // New object reference every render!
5 onSelect={() => handleSelect(id)} // New function reference every render!
6/>
7// Result: React.memo sees different prop references and re-renders anyway!

To fix this, objects must be memoized with useMemo, and functions must be memoized with useCallback.

4. Providing a Custom Comparison Function

If you need deep or selective comparison, React.memo accepts a custom comparison function as its second argument:

1function arePropsEqual(prevProps, nextProps) {
2 // Return true if passing nextProps produces same result as prevProps
3 return prevProps.course.id === nextProps.course.id &&
4 prevProps.course.updatedAt === nextProps.course.updatedAt;
5}
6 
7export default memo(CourseSummaryCard, arePropsEqual);

(Notice: Return true to SKIP render; return false to RE-RENDER. This is the opposite of shouldComponentUpdate!)

5. When NOT to Use React.memo

Do not wrap every component in React.memo!

  • Memoization has a cost: React must run equality checks on every prop before every render.
  • For lightweight components (a simple button or icon), the prop comparison check is often more expensive than just letting the component re-render!
  • Use React.memo only on heavy components, large list items, or components with expensive rendering trees.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does React.memo do when applied to a functional component?
Question 2
Why does passing an unmemoized inline arrow function (onClick={() => doSomething()}) break React.memo on a child component?
Question 3
What should a custom comparison function passed to React.memo(Component, arePropsEqual) return if props are identical and rendering should be skipped?
Question 4
When is using React.memo genuinely beneficial?
Question 5
Does wrapping a component in React.memo prevent it from re-rendering if its OWN internal useState updates?
Next Lesson

The useCallback Hook and Stabilizing Callback Props

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
React Re-render Rules and Profiling BottlenecksThe useCallback Hook and Stabilizing Callback Props

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext