Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

Subscribe to the newsletter

Get new articles and course lessons delivered to your inbox. No spam, unsubscribe anytime.

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 4 of the Advanced React: Performance, Architecture & Patterns course
ReactJune 27, 20263 min read

Strategic use of React.memo: Advanced Component Optimization

Master React.memo to stop unnecessary re-renders. Learn when to memoize, how to write custom comparison functions, and why over-memoization hurts performance.

ReactPerformanceOptimizationComponent ArchitectureWeb Developmentjavascriptfrontend

Previously in this course, we explored Profiling with React DevTools: Identifying Performance Bottlenecks to pinpoint exactly where our application wastes cycles. Now that you can identify why a component re-renders, we move to the "how" of prevention: the strategic application of React.memo.

Understanding the Reconciliation Tax

To understand React.memo, we must recall the Deep Dive into the Reconciliation Algorithm. By default, when a parent component renders, React recursively renders all its children, regardless of whether their props have changed.

If a component is computationally expensive or lives deep in a complex tree, this default behavior leads to "render cascades." React.memo is a higher-order component that tells React to skip rendering a component if its props have not changed. It wraps your component and performs a shallow comparison of the new props against the previous props.

Identifying Candidates for Memoization

Not every component should be wrapped in React.memo. Applying it indiscriminately adds a "memoization tax"—the overhead of comparing props every time the parent renders.

You should target components that meet these criteria:

  1. High Frequency: Components that re-render often due to a parent’s state (e.g., inputs, animations, list items).
  2. Heavy Rendering: Components that perform significant DOM work or contain complex sub-trees.
  3. Pure Components: Components that consistently return the same output given the same props.

Implementing Custom Comparison Functions

By default, React.memo uses Object.is for shallow comparison. If your component receives objects or arrays as props, the default check will fail because those references change on every render.

For these cases, we provide a custom comparison function as the second argument:

JAVASCRIPT
const UserProfile = React.memo(({ user, settings }) => {
  console.log("Rendering UserProfile...");
  return <div>{user.name}</div>;
}, (prevProps, nextProps) => {
  // Only re-render if user ID or specific settings changed
  return (
    prevProps.user.id === nextProps.user.id &&
    prevProps.settings.theme === nextProps.settings.theme
  );
});

This function returns true if the props are equal (preventing a re-render) and false if they are different (triggering a re-render).

Advancing the Project: Optimizing the Dashboard

In our running project, the DashboardGrid re-renders every time the global filter state changes. However, the individual ChartWidget components don't need to update unless their specific data slice changes.

We will wrap our ChartWidget in React.memo and implement a custom equality check to ensure that only relevant prop updates trigger a redraw.

Hands-on Exercise

Find a list-based component in your current project. Use the React DevTools Profiler to confirm it re-renders whenever the parent state updates. Wrap an item component in React.memo and verify the reduction in "Why did this render?" messages in the profiler.

Challenge: If you pass a callback function to your item component, notice how it still re-renders. We will solve this in the next lesson using useCallback.

Common Pitfalls

  • The "Memoization Tax": If a component is cheap to render, the cost of the shallow comparison might actually be higher than just re-rendering the component. Don't memoize leaf nodes like simple buttons or spans.
  • Prop Reference Instability: Memoization fails if you pass inline objects or functions: <Child data={{ id: 1 }} />. Even if id is the same, { id: 1 } !== { id: 1 }. Always define objects/functions outside the component or use useMemo/useCallback.
  • Ignoring the Second Argument: Developers often rely on default shallow comparison when passing complex objects, leading to "false negatives" where the component never updates even when data changes.

Recap

React.memo is a surgical tool, not a performance panacea. Use it to prune the render tree when profiling confirms that unnecessary re-renders are impacting user experience. Always prioritize memoizing high-level components that sit above large sub-trees, and be wary of the overhead introduced by custom comparison functions on frequently updating components.

Up next: We’ll tackle the primary cause of React.memo failure: unstable prop references. We will master useCallback and useMemo to ensure our memoization strategies actually hold up in production.

Previous lessonEstablishing Performance BudgetsNext lesson Mastering useCallback and useMemo
Back to Blog

Similar Posts

ReactJune 26, 20264 min read

Optimizing Asset Loading: Performance, Lazy Loading, Code Splitting

Master performance optimization in React. Learn how to use lazy loading, code splitting, and image optimization to keep your dashboard fast and efficient.

Read more
ReactJune 27, 20264 min read

Optimizing Context Providers: Scaling React Performance

Learn to prevent tree-wide re-renders in your React application by optimizing Context Providers through value memoization, state splitting, and selective hooks.

Part of the course

Advanced React: Performance, Architecture & Patterns

advanced · Lesson 4 of 47

  1. 1

    Deep Dive into the Reconciliation Algorithm

    4 min
  2. 2

    Profiling with React DevTools

    3 min
  3. 3

    Establishing Performance Budgets

    3 min
Read more
ReactPerformanceJune 26, 20263 min read

Profiling with React DevTools: Identifying Performance Bottlenecks

Stop guessing why your React app is slow. Master the React Profiler to record sessions, analyze flame graphs, and pinpoint performance bottlenecks in your code.

Read more
  • 4

    Strategic use of React.memo

    3 min
  • 5

    Mastering useCallback and useMemo

    4 min
  • 6

    State Colocation Strategies

    4 min
  • 7

    Optimizing Context Providers

    4 min
  • 8

    Advanced Context Composition

    4 min
  • 9

    Eliminating Prop Drilling

    4 min
  • 10

    Introduction to Concurrent React

    4 min
  • 11

    Non-blocking UI with useTransition

    4 min
  • 12

    Handling Deferred Data with useDeferredValue

    3 min
  • 13

    Mastering Suspense for Data Fetching

    4 min
  • 14

    Streaming Server-Side Rendering

    3 min
  • 15

    Designing Compound Components

    3 min
  • 16

    The Render Props Pattern

    4 min
  • 17

    Implementing Control Props

    4 min
  • 18

    Headless UI Architectures

    3 min
  • 19

    Modular Directory Structures

    3 min
  • 20

    Refactoring Monolithic Components

    3 min
  • 21

    Optimistic UI Updates

    3 min
  • 22

    Advanced Cache Invalidation

    4 min
  • 23

    Handling Race Conditions

    4 min
  • 24

    Server-Client State Synchronization

    3 min
  • 25

    Route-level Code Splitting

    4 min
  • 26

    Offloading Tasks with Web Workers

    3 min
  • 27

    Advanced Error Boundaries

    3 min
  • 28

    Monitoring Production Performance

    4 min
  • 29

    Final Project Audit & Optimization

    Coming soon
  • 30

    Advanced Hook Patterns

    Coming soon
  • 31

    Managing Global State with Zustand/Redux

    Coming soon
  • 32

    Testing Performance-Critical Components

    Coming soon
  • 33

    Static Site Generation (SSG) Patterns

    Coming soon
  • 34

    Internationalization (i18n) Architecture

    Coming soon
  • 35

    Accessibility (a11y) in Advanced Components

    Coming soon
  • 36

    Managing Third-Party Integrations

    Coming soon
  • 37

    Advanced Form Handling

    Coming soon
  • 38

    Using Portals for UI Overlays

    Coming soon
  • 39

    Implementing Virtualized Lists

    Coming soon
  • 40

    Building Design System Primitives

    Coming soon
  • 41

    Managing Large-Scale Data Fetching

    Coming soon
  • 42

    Micro-Frontends with React

    Coming soon
  • 43

    Security Best Practices in React

    Coming soon
  • 44

    Advanced Ref Usage

    Coming soon
  • 45

    Memoization Pitfalls

    Coming soon
  • 46

    Mastering React Patterns for Scalability

    Coming soon
  • 47

    Advanced TypeScript with React

    Coming soon
  • View full course