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

React Project Structure

Understand the folders, files, entry point, root component, dependencies, and configuration of a React project created with Vite.

1. What Is React Project Structure?

React project structure refers to the organization of folders and files used to build and manage a React application. Each file has a specific responsibility, such as defining components, adding styles, loading the application, or managing project dependencies.

When we create a React project using Vite, Vite generates an initial folder structure. We can organize additional components, pages, styles, and other files as our application grows.

Remember: Understanding the project structure helps you find the correct file when you want to change the UI, add a component, install a package, or troubleshoot an error.

2. React Project Structure Diagram

This is an example of the common folder structure generated for a Vite React application.

📁 my-react-app Project Root
📁 node_modules Installed Packages
📁 public Static Assets
📁 src Application Source Code
📄 App.jsx Main UI Component
📄 App.css App Component Styles
📄 index.css Global Styles
📄 main.jsx React Entry Point
📄 index.html HTML Entry Document
📄 package.json Scripts and Dependencies
📄 package-lock.json Dependency Lockfile
📄 vite.config.js Vite Configuration (If Present)
📄 .gitignore Git Ignore Rules
Note: The exact files depend on the Vite version and selected template. Some files are optional or may not be generated by every template.

3. Understanding the Project Root

The project root is the main folder of your React application. It contains the source code folder, package information, configuration files, and other project resources.

📁

my-react-app

The main directory where you run npm commands and manage the project.

Important Root-Level Files

JSON

package.json

Contains project metadata, dependencies, and commands such as npm run dev.

LOCK

package-lock.json

Records the resolved dependency tree used by npm to support consistent installs.

HTML

index.html

Provides the HTML document and the root element where the React application is mounted.

CONFIG

vite.config.js

Configures Vite when the project includes and uses this configuration file.

4. Understanding the src Folder

The src folder contains the main application source code. This is where you will usually create and maintain React components and their styles.

📁

src

Application Source Code

📄

main.jsx

Starts React rendering

📄

App.jsx

Defines the main UI

🎨

App.css

Styles the app component

🎨

index.css

Provides global styles

Practical tip: When you start building larger applications, you can add folders such as components, pages, assets, and services inside src to organize your code.

5. What Is main.jsx?

The main.jsx file is commonly the entry point of a Vite React application. It imports React-related functions and the root component, then mounts the component inside an HTML element.

src/main.jsx JSX
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(
    <StrictMode>
        <App />
    </StrictMode>
);

Code Explanation

StrictMode

Helps identify potential problems during development.

createRoot()

Creates a React root for the target HTML element.

document.getElementById('root')

Finds the HTML element whose ID is root.

<App />

Renders the application's root component.

6. What Is App.jsx?

The App.jsx file commonly contains the root application component. It can combine smaller components to build the overall user interface.

src/App.jsx React Component
function Header() {
    return <h1>CIIT Training Institute</h1>;
}

function CourseList() {
    return (
        <div>
            <p>Java Full Stack</p>
            <p>React Development</p>
            <p>Python Full Stack</p>
        </div>
    );
}

function App() {
    return (
        <div>
            <Header />
            <CourseList />
        </div>
    );
}

export default App;

Expected Browser Output

Example Output

CIIT Training Institute

Java Full Stack

React Development

Python Full Stack

Remember: This output is an illustration. You will see it in your browser when this component is used in a correctly running React project.

7. What Is index.html?

The index.html file is the HTML entry document served by Vite. In a typical Vite React template, it contains a root element and a script that loads main.jsx.

index.html HTML
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My React App</title>
</head>
<body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
</body>
</html>
Important: The id="root" value must match the element selected in main.jsx. This is where the React tree is mounted in this example.

8. What Is package.json?

The package.json file stores project metadata, scripts, and dependency declarations. npm uses the scripts defined here when you run commands such as npm run dev.

package.json JSON
{
  "name": "my-react-app",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "project-installed-version",
    "react-dom": "project-installed-version"
  },
  "devDependencies": {
    "vite": "project-installed-version"
  }
}
Example only: This is a simplified illustration, not a ready-to-use package.json. Keep the actual version ranges and dependencies generated by your project.

Important npm Commands

npm run dev

Starts the development server.

npm run build

Builds the application for production.

npm run preview

Previews the production build locally when it exists.

9. Understanding public and node_modules

📁

public

Stores static files that need to be served as-is, such as a favicon or other publicly accessible assets.

  • Favicon files
  • Static images
  • Other public resources
📦

node_modules

Contains installed packages used by the project and its development tools.

  • React packages
  • Vite and other dependencies
  • Packages installed by npm
Important: Do not manually edit files inside node_modules. npm manages this folder. It is generally excluded from Git using .gitignore.

10. Organizing a React Application

As your React project becomes larger, you can create additional folders inside src. The following is an example of a more organized application structure.

📁 src
📁 components Reusable UI Parts
📄 Header.jsx
📄 CourseCard.jsx
📁 pages Page Components
📄 Home.jsx
📁 assets Imported Images and Assets
📁 services API and Data Services
📄 App.jsx
📄 main.jsx
UI

components

Stores reusable UI pieces such as Header and CourseCard.

PAGE

pages

Stores larger components representing application pages.

ASSETS

assets

Stores assets imported and processed by the application.

API

services

Can contain reusable API requests and data-related functions.

Remember: These extra folders are an example organizational choice. Vite does not require every React project to use exactly this structure.

11. How the Main Files Work Together

1

index.html

Provides the root HTML element and loads the entry script.

↓
2

main.jsx

Creates a React root and renders the App component.

↓
3

App.jsx

Defines the main UI and composes child components.

↓
4

Browser UI

The user sees the rendered application.

12. Practice Task

Task: Explore Your Vite React Project

  1. Open your project folder in Visual Studio Code.
  2. Find the src folder.
  3. Open and read main.jsx.
  4. Open App.jsx and identify the root component.
  5. Open index.html and locate the root element.
  6. Open package.json and check its scripts.
  7. Create a components folder inside src.
  8. Explain the role of each important file in your own words.

Summary

  • The project root contains source code and project configuration files.
  • The src folder contains the main application source code.
  • main.jsx commonly serves as the React entry point.
  • App.jsx commonly defines the root component.
  • index.html provides the HTML root element.
  • package.json stores project scripts and dependencies.
  • node_modules contains installed packages.
  • Additional folders help organize larger applications.