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

Hooks Introduction

Learn what React Hooks are, why they are used, and how they help functional components manage state and other React features.

1. What Are React Hooks?

React Hooks are special functions that allow functional components to use React features such as state, side effects, references, and context.

Hooks were introduced in React 16.8. Before Hooks, state management and lifecycle features were commonly handled using class components. Hooks allow developers to use many of these features directly inside functional components.

Remember: Hooks are functions whose names generally begin with use, such as useState, useEffect, and useRef.

2. Why Do We Use React Hooks?

React Hooks make it easier to manage component state, handle side effects, reuse stateful logic, and work with React features inside functional components.

  • Manage and update component state.
  • Perform side effects such as fetching data.
  • Access and share values through React Context.
  • Store references to values or DOM elements.
  • Reuse logic through custom Hooks.

3. How React Hooks Work

A functional component calls a Hook to access a particular React feature. React manages that feature and updates the component when necessary.

Functional Component
→
Call a Hook
→
Use React Feature
→
Updated UI
Example: When a component updates state using useState, React schedules a re-render so the UI can display the updated value.

4. Commonly Used React Hooks

useState

Used to add and update state in a functional component.

useEffect

Used to synchronize a component with external systems, such as browser APIs, subscriptions, or network requests.

useRef

Used to keep a mutable value between renders or reference a DOM element without causing a re-render when the reference changes.

useContext

Used to read values provided by a React Context.

useReducer

Used to manage state through a reducer function, especially when state transitions involve more complex logic.

useMemo and useCallback

Used to cache calculated values and function definitions when memoization is useful for performance.

Custom Hooks

Custom Hooks allow developers to reuse stateful logic across multiple functional components.

5. Simple Example of a React Hook

The following example uses useState to store and update a counter value.

Example Code

import { useState } from "react";

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

    return (
        <div>
            <h2>React Hooks Example</h2>

            <p>Count: {count}</p>

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

export default App;

Expected Output

React Hooks Example

Count: 0

After clicking Increase Count once, the count becomes 1.

Explanation: The useState(0) Hook initializes the counter with the value 0. The setCount() function updates the state, and React re-renders the component to display the new count.

6. Rules of React Hooks

  • Call Hooks at the top level of a functional component or another custom Hook.
  • Do not call Hooks inside loops, conditions, or nested functions.
  • Call Hooks only from React function components or custom Hooks.
  • Do not call Hooks from ordinary JavaScript functions that are not custom Hooks or React components.
Important: Following the Rules of Hooks helps React preserve the correct state and Hook order between renders.

7. Practice Tasks

Complete the following practice tasks:

  1. Explain React Hooks in your own words.
  2. List five commonly used React Hooks.
  3. Create a functional component that uses useState.
  4. Create a counter with an Increase button.
  5. Explain why Hooks should not be called inside conditions.

Summary

React Hooks are special functions that allow functional components to use React features such as state, side effects, context, and references. Common Hooks include useState, useEffect, useRef, useContext, and useReducer, while custom Hooks help developers reuse stateful logic. Hooks must be called at the top level of React function components or custom Hooks, following the Rules of Hooks. Understanding Hooks provides the foundation for building interactive and maintainable React applications at CIIT Training Institute.