Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogCoursesPhotosContact
Mahamudul Hasan Rubel

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

Navigation

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

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 40 of the React Fundamentals: Build Modern UIs from Scratch course
ReactJune 25, 20263 min read

Performance Optimization Basics: Mastering React Re-rendering

Performance optimization in React starts with understanding re-rendering. Learn how to identify bottlenecks and keep your UI responsive and fast.

Reactperformancere-renderingoptimizationweb-developmentjavascriptfrontend

Previously in this course, we explored introduction to proptypes-catching-bugs-with-react-type-checking to ensure our data flows correctly throughout our movie-browser app. Now that our components are robust, it’s time to ensure they are fast.

In React, "fast" often means avoiding unnecessary work. Today, we’ll dive into performance optimization by dissecting how React decides when to update the screen and how you can prevent the performance pitfalls that lead to sluggish UIs.

Understanding the Re-rendering Cycle

When you change state in a component, React schedules a re-render. This doesn’t mean the entire DOM is wiped and replaced—thanks to the understanding-the-virtual-dom-and-react-performance, React only updates what actually changed.

However, a "re-render" means React calls your function component again to see what it wants to return. If you have a complex component tree, a state change at the top can trigger a cascade of re-renders for every single child component, even if their specific props haven't changed. This is the primary source of "performance lag" in beginner React apps.

Identifying Bottlenecks

Before you start "optimizing," you must identify where the work is happening. The most common sign of a performance issue is a "stutter" during user interactions, like typing in a search bar or toggling a filter.

To see this in action, add a console.log at the top of your MovieCard component:

JSX
function MovieCard({ movie }) {
  console.log("Rendering MovieCard:", movie.title);
  return (
    <div className="card">
      <h3>{movie.title}</h3>
    </div>
  );
}

Now, open your browser console and interact with your app. If you change a filter or search, notice how many times "Rendering MovieCard" appears. If you have 50 movies, you’ll see 50 logs every time the parent component updates, even if only one movie card actually needs to change.

Basic Optimization Strategies

The golden rule of optimization is: don't optimize until you have a measurable problem. However, there are simple architectural habits that prevent these issues from growing.

1. Component Extraction

The most effective way to prevent unnecessary re-renders is to keep your state as "local" as possible. If a part of your UI doesn't need to change when a specific piece of state updates, move that UI into its own component.

2. Using React.memo

React.memo is a higher-order component that tells React: "If the props haven't changed, don't re-render this component." It performs a shallow comparison of the new props versus the old ones.

Let’s wrap our MovieCard:

JSX
import React from CE9178">'react';

const MovieCard = React.memo(({ movie }) => {
  console.log("Rendering MovieCard:", movie.title);
  return (
    <div className="card">
      <h3>{movie.title}</h3>
    </div>
  );
});

export default MovieCard;

Now, when the parent MovieList re-renders due to a filter change, React checks if the movie object reference is the same. If it is, it skips the MovieCard render entirely.

Hands-on Exercise: The "Expensive" Header

In your movie browser, create a Header component that displays the app title and a ThemeToggle button.

  1. Add a console.log to the Header component.
  2. Notice that every time you type in your search bar (which updates state in the parent), the Header re-renders, even though its content never changes.
  3. Wrap your Header in React.memo to prevent it from re-rendering when the search input state updates.

Common Pitfalls

  • Premature Optimization: Wrapping every single component in React.memo actually hurts performance. The comparison process itself has a cost. Only use it for components that render frequently or contain expensive logic.
  • Object/Array References: If you pass an object or array directly as a prop (e.g., style={{ color: 'red' }}), React sees a "new" object every render because the reference changes. This renders React.memo useless. Define these constants outside the component or use useMemo.
  • Ignoring the Key Prop: As we covered in the-key-prop-explained-mastering-react-lists-and-performance, using the wrong key (like an index) forces React to re-render list items unnecessarily. Always use stable, unique IDs.

Recap

Performance optimization is about reducing the workload during the render phase. By moving state closer to where it's used and selectively using React.memo for expensive components, you ensure your app remains responsive as it grows. Remember: observe, identify, then act.

Up next: We’ll explore how to handle browser history and navigation without page refreshes.

Previous lessonIntroduction to PropTypesNext lesson Handling Browser History
Back to Blog

Similar Posts

ReactReactJune 25, 20263 min read

Fetching Data from an API: A Practical React Guide

Master the fetch API in React to retrieve external data. Learn to perform asynchronous requests and store JSON responses in your component state effectively.

Read more
ReactReactJune 25, 20263 min read

Part of the course

React Fundamentals: Build Modern UIs from Scratch

beginner · Lesson 40 of 49

  1. 1

    Introduction to Component-Based Architecture

    4 min
  2. 2

    Understanding the Virtual DOM

    4 min
  3. 3

    Setting Up with Vite

    3 min

Building a Movie Filter Toggle in React: A Beginner's Guide

Master the art of UI state management by adding a filter toggle to your movie app. Learn to control list rendering using boolean state and checkbox inputs.

Read more
ReactReactJune 25, 20264 min read

Rendering Lists of Data in React: A Practical Guide

Learn how to use the map method for list rendering in React. Master the key prop to keep your dynamic movie lists efficient, performant, and bug-free.

Read more
4

Mastering JSX Syntax

4 min
  • 5

    Creating Static Components

    3 min
  • 6

    Styling Components

    3 min
  • 7

    Passing Data with Props

    3 min
  • 8

    Dynamic Movie Cards

    3 min
  • 9

    Component Composition

    3 min
  • 10

    Conditional Rendering

    3 min
  • 11

    Rendering Lists of Data

    4 min
  • 12

    The Key Prop Explained

    4 min
  • 13

    Introduction to React State

    4 min
  • 14

    Managing State with useState

    3 min
  • 15

    Building an Interactive Search Bar

    3 min
  • 16

    Handling Click Events

    4 min
  • 17

    Updating State Based on Previous State

    4 min
  • 18

    Filtering the Movie List

    3 min
  • 19

    Handling Form Submissions

    3 min
  • 20

    Controlled Components

    4 min
  • 21

    Event Bubbling and Propagation

    3 min
  • 22

    Building a Movie Filter Toggle

    3 min
  • 23

    Introduction to Side Effects

    4 min
  • 24

    useEffect Dependencies

    4 min
  • 25

    Fetching Data from an API

    3 min
  • 26

    Handling Loading States

    3 min
  • 27

    Managing Errors

    3 min
  • 28

    Cleanup Functions in useEffect

    3 min
  • 29

    Debouncing Search Input

    3 min
  • 30

    Refactoring for Clean Code

    3 min
  • 31

    Folder Structure Best Practices

    4 min
  • 32

    Extracting Custom Hooks

    3 min
  • 33

    Prop Drilling and Context API

    3 min
  • 34

    Polishing the UI

    3 min
  • 35

    Finalizing the Movie Browser

    3 min
  • 36

    Review of Component Lifecycle

    4 min
  • 37

    Review of State Management

    4 min
  • 38

    Building a Modal Component

    3 min
  • 39

    Introduction to PropTypes

    3 min
  • 40

    Performance Optimization Basics

    3 min
  • 41

    Handling Browser History

    3 min
  • 42

    Working with LocalStorage

    3 min
  • 43

    Building a Favorites List

    3 min
  • 44

    Handling Media in React

    3 min
  • 45

    Introduction to Testing

    4 min
  • 46

    Debugging React Apps

    4 min
  • 47

    Deployment Basics

    Coming soon
  • 48

    Using External Libraries

    Coming soon
  • 49

    Advanced

    Coming soon
  • View full course