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

Class Components in React

Understand class-based components, render methods, props and state with practical examples from CIIT Training Institute.

Beginner Friendly Practical Examples Expected Output Included

01 Learning Objectives

After completing this lesson, you will be able to:

01
Create Class Components

Define a React component using a JavaScript class.

02
Understand render()

Return JSX from the render method.

03
Use Props

Receive student and course information from a parent.

04
Understand State

Manage component data and update the displayed UI.

02 What Is a Class Component?

A Class Component is a React component defined using an ES6 JavaScript class that extends React.Component. It uses a render() method to return JSX.

Remember: A class component extends React.Component and implements a render() method.
Welcome.jsx JSX
import React from "react";

class Welcome extends React.Component {
    render() {
        return (
            <div>
                <h2>Welcome to CIIT Training Institute!</h2>
                <p>Learn React step by step.</p>
            </div>
        );
    }
}

export default Welcome;
App.jsx JSX
import Welcome from "./Welcome";

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

export default App;
Expected Browser Output

Welcome to CIIT Training Institute!

Learn React step by step.

03 Class Component Flow Diagram

A class component extends React.Component. Its render method returns JSX, which React uses to display the component's UI.

CIIT TRAINING INSTITUTE — CLASS COMPONENT STRUCTURE
BASE CLASS React.Component React component base class
YOUR CLASS StudentInfo extends React.Component
METHOD render() Returns JSX
BROWSER Rendered UI Student information appears on screen
React.Component → StudentInfo → render() → Browser UI
StudentInfo.jsx JSX
import React from "react";

class StudentInfo extends React.Component {
    render() {
        return (
            <div>
                <h2>Student Information</h2>
                <p>Name: Samadhan</p>
                <p>Course: React JS</p>
            </div>
        );
    }
}

export default StudentInfo;
Expected Browser Output

Student Information

Name: Samadhan

Course: React JS

04 Class Components with Props

Props allow a class component to receive data from its parent. Inside a class component, props are accessed using this.props.

StudentCard.jsx JSX
import React from "react";

class StudentCard extends React.Component {
    render() {
        return (
            <div>
                <h3>{this.props.name}</h3>
                <p>Course: {this.props.course}</p>
            </div>
        );
    }
}

export default StudentCard;
App.jsx JSX
import StudentCard from "./StudentCard";

function App() {
    return (
        <div>
            <h2>CIIT Student Profiles</h2>

            <StudentCard
                name="Samadhan"
                course="React JS"
            />

            <StudentCard
                name="Samiksha"
                course=".NET Full Stack"
            />

            <StudentCard
                name="Pradnya"
                course="Python"
            />
        </div>
    );
}

export default App;
Expected Browser Output

CIIT Student Profiles

Samadhan Course: React JS
Samiksha Course: .NET Full Stack
Pradnya Course: Python

05 State in Class Components

State stores data managed by a component. In class components, state is initialized in the constructor and updated using this.setState().

Important: Do not update state directly using this.state.count = 10. Use this.setState() to request a state update.
Counter.jsx JSX
import React from "react";

class Counter extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            count: 0
        };
    }

    increaseCount = () => {
        this.setState((previousState) => ({
            count: previousState.count + 1
        }));
    };

    render() {
        return (
            <div>
                <h2>CIIT Counter</h2>
                <p>Count: {this.state.count}</p>
                <button onClick={this.increaseCount}>
                    Increase
                </button>
            </div>
        );
    }
}

export default Counter;
Expected Browser Output

CIIT Counter

Count: 0

Initial display: Count is 0. In the actual React app, clicking Increase changes the count to 1, then 2, and so on.

06 Class Component Lifecycle

Class components provide lifecycle methods that run at different stages of a component's life.

01 Mounting componentDidMount()

Runs after the component is mounted.

↓
02 Updating componentDidUpdate()

Runs after an update is committed.

↓
03 Unmounting componentWillUnmount()

Runs before the component is removed.

LifecycleDemo.jsx JSX
import React from "react";

class LifecycleDemo extends React.Component {
    componentDidMount() {
        console.log("Component mounted");
    }

    componentDidUpdate() {
        console.log("Component updated");
    }

    componentWillUnmount() {
        console.log("Component will unmount");
    }

    render() {
        return (
            <h2>CIIT Lifecycle Demo</h2>
        );
    }
}

export default LifecycleDemo;
Expected Browser Output

CIIT Lifecycle Demo

The heading appears in the browser. Lifecycle messages appear in the browser developer console when their corresponding lifecycle stages occur.

Console — after mounting Component mounted

07 Functional Components vs Class Components

Feature Functional Component Class Component
Definition JavaScript function JavaScript class
UI rendering Returns JSX Uses render()
State useState and other Hooks this.state and this.setState()
Props Function parameters this.props
Lifecycle Effects and other Hooks Lifecycle methods
Modern React Recommended for new components Supported, often used in legacy code

08 Important Rules and Best Practices

✓

Extend React.Component when defining a class component.

✓

Define a render() method that returns JSX.

✓

Access class component props through this.props.

✓

Update state with this.setState(), not direct assignment.

✓

Use lifecycle methods only when their behavior is needed.

✓

Prefer functional components with Hooks for most new React code.

09 Practice Questions

  1. Create a class component named InstituteInfo.
  2. Create a StudentInfo class component for Samadhan.
  3. Create a reusable class component that receives name and course props.
  4. Create a counter using class state and this.setState().
  5. Write a component that logs a message in componentDidMount().
  6. Explain the difference between functional and class components.

Summary

Class Components are defined using JavaScript classes that extend React.Component and use the render() method to return JSX. They access incoming data through this.props, manage component state with this.state and this.setState(), and support lifecycle methods such as componentDidMount() and componentWillUnmount(). Although class components remain supported, functional components with Hooks are generally preferred for new React development at CIIT Training Institute.