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

Installing React Router

In this lesson, we will install React Router, understand the installation command, and prepare a React project for routing.

1. Why Do We Install React Router?

React does not include a complete routing solution by default. React Router is a separate library that provides routing components and hooks for navigating between views.

Before using components such as BrowserRouter, Routes, Route, and Link, we need to install the appropriate React Router package in our project.

Remember: Install React Router in the React project where you want to use its routing features.

2. Prerequisites

Before installing React Router, make sure you have:

  • Node.js installed on your computer.
  • npm available in your terminal.
  • A React project created on your system.
  • A code editor such as Visual Studio Code.

Check Node.js

node -v

Check npm

npm -v

These commands display the installed versions of Node.js and npm.

3. Create a React Project

If you do not already have a React project, you can create one using Vite.

npm create vite@latest react-routing-demo -- --template react

Move into the newly created project directory.

cd react-routing-demo

Install the project's existing dependencies.

npm install

If you already have a React project, skip the project creation command and open your existing project folder.

4. Install React Router

Open a terminal in your React project directory and run the following command for the declarative routing examples in this module.

npm install react-router-dom

npm downloads the package and adds it to the project's dependencies.

Check package.json

After installation, you can check the dependencies section of your package.json file.

{
  "dependencies": {
    "react": "...",
    "react-dom": "...",
    "react-router-dom": "..."
  }
}

The dots represent version values managed by npm; they are placeholders in this example, not literal package versions.

5. Understand the Installation Workflow

Create or Open React Project
↓
Open Project Terminal
↓
Run npm install react-router-dom
↓
Import React Router Components
↓
Configure Application Routes

Once installation is complete, the application can import React Router components and configure routes.

6. Import React Router Components

After installation, you can import the components needed for routing from react-router-dom.

import {
    BrowserRouter,
    Routes,
    Route,
    Link
} from 'react-router-dom';

These imports make the selected routing components available to your React code.

  • BrowserRouter: Enables browser-based routing.
  • Routes: Groups route definitions.
  • Route: Defines a URL path and its element.
  • Link: Provides client-side navigation.

7. Test the React Project

Start the development server from your project directory.

npm run dev

Vite displays a local development URL in the terminal. Open that URL in your browser to view the React application.

Expected Result

  • The development server starts successfully.
  • The browser displays your React application.
  • The project is ready for routing configuration.

Important: Installing React Router alone does not automatically configure your routes. You must set up the router and define the required paths.

8. Common Installation Problems

Problem 1: npm is not recognized

Node.js may not be installed correctly, or its installation directory may not be available in the system PATH. Install Node.js and reopen the terminal.

Problem 2: Wrong project directory

Make sure the terminal is open in the React project directory containing package.json before running the installation command.

Problem 3: Package installation fails

Check your internet connection, npm error message, and project dependency compatibility before trying again.

Problem 4: Import error

Verify that the package is installed in the correct project and that the import statement uses the correct package name.

Practice Tasks

  1. Check the installed Node.js and npm versions.
  2. Create a new React project using Vite.
  3. Install the project dependencies using npm install.
  4. Install React Router using npm install react-router-dom.
  5. Locate react-router-dom in package.json.
  6. Import BrowserRouter, Routes, Route, and Link.
  7. Start the development server using npm run dev.
  8. Write down any installation error and explain how you resolved it.

Summary

React Router is installed as a package in a React project using npm install react-router-dom. Before installation, ensure that Node.js, npm, and a React project are available. After installing the package, import the required routing components and start the development server to test the application. In the next lesson, we will learn how to configure BrowserRouter and set up routing in a React application.