KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
⚛️

React

Topic Hub & Articles

React Intro

10 min

Recap Quiz

5 Questions

React Getting Started

10 min

React ES6

10 min

React Render HTML

10 min

Recap Quiz

5 Questions

React JSX

10 min

React Components

10 min

React Class Components

10 min

Recap Quiz

5 Questions

React Props

10 min

React Events

10 min

React Conditionals

10 min

Recap Quiz

5 Questions

React Lists

10 min

React Forms

10 min

React Router

10 min

Recap Quiz

5 Questions

React Memo

10 min

React CSS Styling

10 min

React Sass Styling

10 min

Recap Quiz

5 Questions

React Fragments

10 min

React Portals

10 min

React Profiler

10 min

Recap Quiz

5 Questions

React Strict Mode

10 min

React Higher Order Components

10 min

React Context API

10 min

React Error Boundaries

10 min

What is a Hook

10 min

Recap Quiz

5 Questions

useState

10 min

useEffect

10 min

useContext

10 min

Recap Quiz

5 Questions

useRef

10 min

useReducer

10 min

useCallback

10 min

Recap Quiz

5 Questions

useMemo

10 min

Custom Hooks

10 min

useLayoutEffect

10 min

Recap Quiz

5 Questions

useImperativeHandle

10 min

useDebugValue

10 min

useDeferredValue

10 min

Recap Quiz

5 Questions

useTransition

10 min

useId

10 min

Progress
0%

0 / 38 Lessons

ReactReact Tutorial
Lesson

React Memo

10 min reading
Free Course

React Memo: Preventing Unnecessary Component Re-renders

By default, when a parent component re-renders in React, all of its child components automatically re-render as well—even if the child's props haven't changed.

React.memo is a higher-order component (HOC) that memoizes rendering results. If a component's props remain unchanged between renders, React skips rendering the component and reuses the previous rendered output.

Memoization Workflow

flowchart TD
    Parent["Parent Re-renders"] --> Child["Child wrapped in React.memo(Child)"]
    Child --> Check{"Have Props Changed?"}
    Check -- Yes --> Render["Re-render Child Component"]
    Check -- No --> Skip["Skip Render & Reuse Cached Virtual DOM"]

Practical Code Example

import React, { useState, memo } from 'react';

// Memoized Expensive Component
const ExpensiveChild = memo(function ExpensiveChild({ count }) {
  console.log('ExpensiveChild rendered!');
  return (
    <div className="memo-box">
      <h3>Memoized Count: {count}</h3>
    </div>
  );
});

export default function ParentController() {
  const [persistentCount, setPersistentCount] = useState(0);
  const [text, setText] = useState('');

  return (
    <div className="parent-box">
      <h2>React.memo Performance Demo</h2>

      {/* Typing here triggers ParentController re-render */}
      <input 
        type="text" 
        value={text} 
        onChange={(e) => setText(e.target.value)} 
        placeholder="Type here..."
      />

      <button onClick={() => setPersistentCount(prev => prev + 1)}>
        Increment Child Count
      </button>

      {/* ExpensiveChild will NOT re-render when typing in the input box */}
      <ExpensiveChild count={persistentCount} />
    </div>
  );
});

Custom Comparison Function

By default, React.memo performs shallow prop comparison. You can supply a custom comparison function as a second argument for deep or tailored property comparisons:

function arePropsEqual(prevProps, nextProps) {
  return prevProps.item.id === nextProps.item.id;
}

export default memo(MyComponent, arePropsEqual);

Best Practices & Gotchas

  • Do Not Wrap Every Component: Memoization overhead (shallow prop checking) costs CPU memory. Use React.memo only for components that render frequently with heavy sub-trees or large lists.
  • Functions and Objects Break Memoization: Passing inline object literals (style={{ color: 'red' }}) or inline arrow functions (onClick={() => ...}) creates new object references on every parent render, invalidating shallow prop comparison. Combine React.memo with useCallback and useMemo.

Self-Check Challenge

Explain why passing an unmemoized callback function onClick={handleClick} as a prop to a React.memo child causes the child to re-render despite wrapping it in React.memo.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Recommended Courses & Books

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum