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

API Integration Introduction

In this lesson, you will learn what API integration means, how React applications communicate with external services, how data travels between a frontend and a server, and why APIs are important for building real-world applications.

1. What Is an API?

API stands for Application Programming Interface. It provides a defined way for one software application to communicate with another application or service.

For example, a React application may need to display weather information, product details, student records, or employee data. That information may be stored on a remote server rather than directly inside the React application.

The React application can send a request to an API. The server processes that request and returns a response, often containing data in JSON format.

Remember: An API acts as a communication interface between software systems. It defines how requests are made and how responses are returned.

2. What Is API Integration in React?

API integration in React means connecting a React user interface to an API so that the application can request, send, and display data from a server.

Instead of showing only static information written in a component, a React application can retrieve current information from a backend service.

Examples of API Integration

  • Student Management: Retrieve student records.
  • E-commerce: Load product names, prices, and images.
  • Weather Application: Retrieve weather information.
  • Banking Dashboard: Display account information provided by a secure service.
  • Training Institute: Display courses and student details from a database through an API.

3. How API Integration Works

A typical API interaction begins when the React application sends an HTTP request. The server receives the request, performs the required operation, and sends back an HTTP response.

React Component (User Interface)
↓
HTTP Request to API
↓
Backend Server / API
↓
HTTP Response (often JSON)
↓
React Updates and Displays Data

Step-by-Step Explanation

  1. The user opens a React page that needs information.
  2. The React application sends a request to an API endpoint.
  3. The server processes the request and accesses the required data or service.
  4. The server returns an HTTP response, which may contain JSON data.
  5. The React application reads the response and updates its state.
  6. React renders the updated user interface.
An API response can contain successful data or an error response. Applications should handle both cases instead of assuming every request will succeed.

4. What Is an API Endpoint?

An API endpoint is a URL at which a client can access a particular resource or operation provided by an API.

For example, an API might provide an endpoint that returns a list of products.

Example API Endpoint
https://api.example.com/products

In this example, /products identifies the resource being requested. The actual behavior depends on the API's design and the HTTP method used.

Common HTTP Methods

  • GET: Retrieve information.
  • POST: Submit data or create a resource.
  • PUT: Replace a resource.
  • PATCH: Partially update a resource.
  • DELETE: Request deletion of a resource.
These are common conventions for HTTP APIs. The server determines which methods are supported by each endpoint.

5. What Is JSON?

JSON stands for JavaScript Object Notation. It is a text format commonly used to exchange structured data between applications.

An API may return a JSON object containing a student's ID, name, and course.

Example JSON Response
{
    "id": 101,
    "name": "Samadhan",
    "course": "React",
    "isActive": true
}

React can read the response data and use its properties to display information in components. JSON is a data format; it is not itself an API or a programming language.

6. Fetch API in React

JavaScript provides the Fetch API for making HTTP requests. It returns a Promise that can be used to process the response. You will learn its complete usage in the next lesson.

Basic Fetch Example
fetch("https://jsonplaceholder.typicode.com/users")
    .then(response => {
        if (!response.ok) {
            throw new Error("Request failed");
        }

        return response.json();
    })
    .then(data => {
        console.log(data);
    })
    .catch(error => {
        console.error("API Error:", error);
    });

Understanding the Example

  • fetch() sends an HTTP request to the endpoint.
  • response.ok checks whether the HTTP status is in the successful range.
  • response.json() reads the response body and parses JSON data.
  • then() processes the result of a Promise.
  • catch() handles a rejected Promise or an error thrown in the preceding chain.
Fetch does not automatically reject its Promise for HTTP error statuses such as 404 or 500. Checking response.ok allows your code to handle those responses explicitly.

7. Why Do We Need API Integration?

API integration helps React applications work with dynamic data and backend services instead of relying entirely on hardcoded information.

  • It enables applications to retrieve updated information from servers.
  • It allows frontend and backend applications to work together.
  • It supports operations such as retrieving and submitting records.
  • It makes it possible to build interfaces for real-world systems.
  • It allows multiple clients to use a shared backend service when the API is designed for that purpose.

8. Important Things to Remember

  • React handles the user interface; APIs provide access to external data and operations.
  • HTTP requests communicate with API endpoints.
  • JSON is a common format for API request and response data.
  • API requests can fail because of network issues, server errors, or invalid requests.
  • Loading, success, and error states help users understand what is happening.
  • Authentication tokens, API keys, and other secrets must not be exposed in frontend code.
  • Private data and sensitive operations must be protected on the backend.

9. Practice Tasks

Task 1: Understand API Responses

Create a sample JSON object containing a student's ID, name, course, and email. Identify each property and its value.

Task 2: Identify HTTP Methods

Decide whether GET, POST, PUT, PATCH, or DELETE is appropriate for retrieving a student, creating a student, updating a student's course, and deleting a record.

Task 3: Explore an API Endpoint

Open the public example endpoint https://jsonplaceholder.typicode.com/users in your browser and examine the JSON response.

Task 4: Explain the Request Flow

Write the steps that occur when a React component requests product information from an API and displays it to the user.

Summary

In this lesson, you learned what an API is, what API integration means in React, how HTTP requests and responses work, what API endpoints and JSON are, and how the Fetch API can retrieve data. You also explored common HTTP methods, the benefits of connecting React applications to backend services, and the importance of handling errors and protecting sensitive information. In the next lesson, you will learn how to fetch data using the Fetch API in more detail.