Master React From Scratch

Clear, practical, and structured React lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to React
Introduction to React What Is React? Features of React Advantages of React Limitations of React Uses of React React vs JavaScript React Architecture
2. React Getting Started
Getting Started Introduction Prerequisites Installing Node.js and npm Creating a React Project with Vite React Project Structure Running React Application Your First React Application
3. JSX
JSX Introduction What Is JSX? JavaScript Expressions JSX Attributes Rendering JSX Elements JSX Children React Fragments JSX Rules and Best Practices JSX vs HTML
4. React Components
Components Introduction Functional Components Class Components Component Composition Reusable Components Component Tree Component Lifecycle Import and Export Components
5. React Props
Props Introduction What Are Props? Passing Props to Components Props Destructuring Default Props Values Children Props Typing Props with TypeScript Props vs State
6. React State
State Introduction What Is State? useState Hook Updating State Functional State Updates State with Objects State with Arrays State Immutability Lifting State Up
7. React Events
Events Introduction Handling Events Passing Arguments to Event Handlers Synthetic Events Form Events Keyboard and Mouse Events Event Propagation
8. Conditional Rendering
Conditional Rendering Introduction If-Else Rendering Ternary Operator Logical AND Operator Element Variables Preventing Rendering Multiple Conditions Conditional CSS Classes
9. Lists and Keys
Lists and Keys Introduction Rendering Lists with map() Understanding Keys Choosing Unique Keys Lists of Objects Filtering Lists Sorting Lists Empty Lists and Conditional Rendering
10. React Forms
Forms Introduction Handling Forms Controlled Components Uncontrolled Components Handling Input Fields Checkboxes and Radio Buttons Select and Textarea Form Validation Form Submission
11. React Hooks
Hooks Introduction useState Hook useEffect Hook Effect Dependencies and Cleanup useRef Hook useReducer Hook useMemo Hook useCallback Hook Custom Hooks Rules of Hooks
12. React Context API
Context API Introduction createContext useContext Context Provider Reading Context Updating Context Using Multiple Contexts Context API vs Props Context API Best Practices
13. React Routing
Routing Introduction Introduction to React Router Installing React Router BrowserRouter Setup Routes and Route Components Link and NavLink Programmatic Navigation URL Parameters and useParams Nested Routes Not Found Routes Protected Routes
14. API Integration
API Integration Introduction Fetch API Async/Await with API Calls Displaying API Data Loading and Error States Sending POST Requests API Error Handling Using Axios Custom Fetch Hook API Environment Variables
15. State Management
State Management Introduction Global State Prop Drilling Introduction to Redux Redux Core Concepts Redux Toolkit Store and Slices useSelector and useDispatch Async Operations with Redux Toolkit State Management Best Practices
16. React Performance
Performance Introduction Understanding Re-Renders Avoiding Unnecessary Re-Renders React.memo useMemo Optimization useCallback Optimization React Developer Tools and Profiler Lazy Loading Components Code Splitting Optimizing Large Lists Performance Best Practices

Understanding Re-Renders in React

A re-render occurs when React calls a component function again to determine what the user interface should look like. Re-rendering is a normal part of React and helps the application display updated data whenever necessary.

However, when an application contains many components, understanding why and when they render becomes important. It helps developers identify unnecessary work and improve application performance.

Important: A re-render does not automatically mean that the browser DOM will be updated. React compares the rendered result and applies the necessary changes.

1. What Is Rendering?

Rendering is the process in which React executes a component to calculate the UI that should be displayed. For a function component, React calls its function and uses the returned JSX to determine the output.

A component may render when:

  • Its state changes.
  • Its parent component renders again.
  • Its props change as part of an update.
  • A context value it consumes changes.

2. How Does a Re-Render Work?

State / Props / Context Change
↓
React Schedules an Update
↓
Component Function Executes
↓
React Reconciles the Result
↓
Necessary DOM Updates

React may render a component without making any visible DOM changes. It compares the new result with the previous result and updates the DOM when needed.

3. Example: State Change Causes a Re-Render

In this example, the Counter component stores a number in state. Whenever the button is clicked, the state changes and React renders the component again to display the new number.

Counter.jsx
import { useState } from "react";

function Counter() {
    const [count, setCount] = useState(0);

    console.log("Counter rendered");

    return (
        <div>
            <h2>Count: {count}</h2>

            <button onClick={() => setCount(count + 1)}>
                Increase
            </button>
        </div>
    );
}

export default Counter;

Expected Output

Initial display: Count: 0

After one click: Count: 1

After two clicks: Count: 2

The console message "Counter rendered" appears when React executes the component. Development Strict Mode may cause additional render calls.

Explanation

  1. Initially, count is 0.
  2. The user clicks the Increase button.
  3. setCount updates the state to the next value.
  4. React renders the Counter component again.
  5. The heading displays the updated count.

4. Parent and Child Re-Renders

By default, when a parent component renders again, React may also render its child components. This can happen even if a child receives the same primitive prop values as before.

ParentChild.jsx
import { useState } from "react";

function Child({ name }) {
    console.log("Child rendered");

    return <h3>Hello, {name}</h3>;
}

function Parent() {
    const [count, setCount] = useState(0);

    return (
        <div>
            <h2>Count: {count}</h2>

            <button onClick={() => setCount(count + 1)}>
                Increase Count
            </button>

            <Child name="Samadhan" />
        </div>
    );
}

export default Parent;

Expected Behavior

Count: 0

Button: Increase Count

Hello, Samadhan

When the count changes, Parent renders again. Child may also render again, even though its name prop remains "Samadhan".

Remember: A child re-render does not necessarily mean its props changed. Parent rendering can cause child rendering unless React can skip it through an applicable optimization.

5. Re-Rendering Does Not Always Mean a Performance Problem

Re-rendering is essential for displaying updated data. Most simple components render quickly, so trying to prevent every render can make code more complicated without improving the user experience.

  • Necessary re-renders keep the UI synchronized with state.
  • Unnecessary re-renders may waste work in expensive components.
  • React can avoid DOM updates when the rendered output has not changed.
  • Performance should be measured before introducing optimizations.

6. Common Reasons for Re-Renders

State Updates

Calling a state setter with a different value can cause React to render the component again.

Parent Component Updates

When a parent renders, its child components can render again as part of the normal rendering process.

Context Updates

Components that consume a context value may render again when the context value they use changes.

Changed Props

New prop values can affect what a component displays and may require it to render again.

7. Practice Tasks

  1. Create a Counter component using useState.
  2. Add a console message inside a component function.
  3. Create a Parent component with one Child component.
  4. Change the parent's state and observe the console.
  5. Explain the difference between a re-render and a DOM update.
  6. List three common reasons for a component to render again.

Summary

Re-rendering is a normal part of React's rendering process. A component can render again because its state changes, its parent renders, its props change, or a context value it consumes changes. React compares the new rendered result with the previous one and updates the DOM when necessary. Re-renders are not always a performance problem, so developers should understand their causes and measure performance before applying optimizations. CIIT Training Institute recommends practicing with state and parent-child components to understand rendering behavior clearly.