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

Component Lifecycle in React

Understand how React components are created, updated and removed from the user interface at CIIT Training Institute.

Beginner Friendly Practical Examples Expected Output Included

01 Learning Objectives

After completing this lesson, you will be able to:

01
Understand Component Lifecycle

Learn the stages of a React component.

02
Understand Mounting

Learn when a component appears on the screen.

03
Understand Updating

Learn how state changes update the UI.

04
Understand Unmounting

Learn when a component is removed.

02 What Is Component Lifecycle?

The React Component Lifecycle describes the stages a component passes through during its existence. A component can be mounted when it appears, updated when its data changes, and unmounted when it is removed from the UI.

Remember: Functional components commonly use the useEffect() Hook to perform side effects and manage cleanup when necessary.
App.jsx JSX
import { useEffect } from "react";

function Welcome() {
    useEffect(() => {
        console.log("Welcome component mounted");

        return () => {
            console.log("Welcome component unmounted");
        };
    }, []);

    return <h2>Welcome to CIIT Training Institute</h2>;
}

function App() {
    return <Welcome />;
}

export default App;
Expected Browser Output

Welcome to CIIT Training Institute

Console on initial mount:

Welcome component mounted

03 Component Lifecycle Stages

A React component can pass through three important stages: mounting, updating and unmounting.

01

Mounting

The component is created and displayed.

↓
02

Updating

The component renders again when relevant state or props change.

↓
03

Unmounting

The component is removed from the UI and cleanup can run.

Important: An update does not always mean that every effect runs. The dependencies provided to useEffect() determine when that effect runs again.

04 Mounting Phase

Mounting occurs when React adds a component to the UI for the first time. In this example, an effect with an empty dependency array runs after the component commits.

MountingExample.jsx JSX
import { useEffect } from "react";

function CourseWelcome() {
    useEffect(() => {
        console.log("CourseWelcome mounted");
    }, []);

    return (
        <section>
            <h2>React JS Course</h2>
            <p>Welcome to CIIT Training Institute.</p>
        </section>
    );
}

export default CourseWelcome;
Expected Browser Output

React JS Course

Welcome to CIIT Training Institute.

Console on mount:

CourseWelcome mounted

05 Updating Phase with useEffect()

A component can update when its state or props change. The following example uses useState() to update a student's progress and useEffect() to observe changes to that value.

ProgressExample.jsx JSX
import { useEffect, useState } from "react";

function StudentProgress() {
    const [progress, setProgress] = useState(0);

    useEffect(() => {
        console.log("Progress updated:", progress);
    }, [progress]);

    return (
        <section>
            <h2>Samadhan's Learning Progress</h2>
            <p>Progress: {progress}%</p>

            <button onClick={() => setProgress(progress + 10)}>
                Increase Progress
            </button>
        </section>
    );
}

export default StudentProgress;
Expected Browser Output

Samadhan's Learning Progress

Progress: 0%

Click the button in the running React application to increase progress by 10%. The effect logs each updated value.

06 Unmounting Phase

Unmounting occurs when a component is removed from the UI. A cleanup function returned by useEffect() can run when the component unmounts.

UnmountExample.jsx JSX
import { useEffect, useState } from "react";

function StudentMessage() {
    useEffect(() => {
        console.log("StudentMessage mounted");

        return () => {
            console.log("StudentMessage unmounted");
        };
    }, []);

    return <p>Samiksha is learning React JS.</p>;
}

function App() {
    const [showMessage, setShowMessage] = useState(true);

    return (
        <section>
            <button onClick={() => setShowMessage(!showMessage)}>
                Toggle Student Message
            </button>

            {showMessage && <StudentMessage />}
        </section>
    );
}

export default App;
Expected Browser Output

Initially visible:

Samiksha is learning React JS.

After hiding the message, the paragraph disappears.

Console on unmount:

StudentMessage unmounted

07 Understanding the useEffect Dependency Array

The dependency array controls when an effect is re-run. Compare these three common patterns.

No Dependency Array

useEffect(() => { /* effect */ });

The effect runs after every committed render.

Empty Dependency Array

useEffect(() => { /* effect */ }, []);

The effect runs after the initial mount, with cleanup when needed.

With Dependencies

useEffect(() => { /* effect */ }, [count]);

The effect re-runs when a dependency changes.

Note: In development, React Strict Mode may run an extra setup and cleanup cycle to help identify unsafe effect logic. Console output can therefore differ from a production run.

08 Practical Example: Student Dashboard

This example combines mounting and updating. When the student changes the selected course, the effect logs the latest course.

StudentDashboard.jsx JSX
import { useEffect, useState } from "react";

function StudentDashboard() {
    const [course, setCourse] = useState("React JS");

    useEffect(() => {
        console.log("Selected course:", course);
    }, [course]);

    return (
        <section>
            <h2>CIIT Student Dashboard</h2>
            <p>Student: Pradnya</p>
            <p>Selected Course: {course}</p>

            <button onClick={() => setCourse(".NET Full Stack")}>
                Select .NET Full Stack
            </button>
        </section>
    );
}

export default StudentDashboard;
Expected Browser Output

CIIT Student Dashboard

Student: Pradnya

Selected Course: React JS

After selecting another course:

Selected Course: .NET Full Stack

The React application updates the displayed course and logs the new selection in the browser console.

09 Important Rules and Best Practices

✓

Use useEffect() for side effects, not for ordinary rendering calculations.

✓

Include every reactive value used by an effect in its dependency array.

✓

Return a cleanup function when subscriptions, timers or listeners need cleanup.

✓

Do not assume an effect runs only once in every development configuration.

✓

Keep component lifecycle logic simple, readable and maintainable.

10 Practice Questions

  1. What is the React component lifecycle?
  2. Explain mounting, updating and unmounting.
  3. What is the purpose of the useEffect() Hook?
  4. What does an empty dependency array mean?
  5. Why is a cleanup function useful?
  6. Create a student component that logs changes to its course.

Summary

The React Component Lifecycle describes how components are mounted, updated and unmounted. Functional components commonly use the useEffect() Hook to handle side effects and cleanup. Its dependency array determines when the effect runs again. Understanding these stages helps developers build reliable, maintainable interfaces for student dashboards and course pages at CIIT Training Institute.