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

Running React Application

Learn how to start the Vite development server, open your React application in a browser, verify changes, and troubleshoot common errors.

1. Introduction

After creating a React project and installing its dependencies, the next step is to run the application. In a Vite-based React project, we usually start the development server using an npm script.

The development server serves the application locally. You can open the provided URL in a browser, edit your React components, and see the updated interface while developing.

Remember: Before running the application, make sure you are inside the correct project folder and that the project's dependencies have been installed.

2. React Application Execution Flow

This diagram shows the process from starting the development server to viewing your React application.

Step 1

Terminal

Open the React project folder.

↓
Step 2

npm run dev

Start the Vite development server.

↓
Step 3

Vite Development Server

Serves the application on a local URL.

↓
Step 4

Web Browser

Displays the React user interface.

↓
✓

React Application Running

You can now view and test your application.

3. Before Running the Application

📁

React Project

A React project created with Vite.

📦

Dependencies

Required packages installed using npm.

>_

Terminal

Command Prompt, PowerShell, or the VS Code terminal.

🌐

Web Browser

A modern browser to view the application.

4. Step 1: Open the React Project

Open the project folder in Visual Studio Code or navigate to it using a terminal.

For example, if your project is named my-react-app, run the following command from its parent directory:

Terminal Windows Example
cd my-react-app

Verify Your Current Location

You can use the following command in Windows Command Prompt to display the current directory.

Command Prompt Directory
cd
Important: Run React project commands from the folder containing package.json. If you use VS Code, its integrated terminal may already start in your project folder.

5. Step 2: Install Dependencies

If this is a newly created project and its dependencies have not been installed yet, run:

Terminal npm
npm install

npm reads the project's dependency information and installs the packages required by the application.

package.json

Declares dependencies and available npm scripts.

node_modules

Contains the installed project packages.

Note: You do not normally need to run npm install every time you start an already configured project.

6. Step 3: Start the Development Server

Run this command in the project directory:

Terminal Start Application
npm run dev

What Happens When You Run This Command?

1

npm Reads the Script

npm reads the dev script from package.json.

2

Vite Starts

The configured development server starts if the command and dependencies are valid.

3

A Local URL Appears

The terminal shows the URL used to access the app.

Example Terminal Output
VITE ready

Local: http://localhost:5173/

The exact output and port may vary with the installed Vite version and your computer's configuration.

7. Step 4: Open the Application in a Browser

Once Vite displays the local URL, open it in a modern web browser. The default URL commonly uses port 5173, but always use the URL shown in your terminal.

http://localhost:5173/
Example Browser View

Welcome to React!

Your React application is running.

✓ Development server connected
Important: The browser mockup above illustrates a possible application screen. Your actual page will depend on the code currently inside your React components.

8. Step 5: Change the React Application

Now open src/App.jsx and replace its contents with the following example.

src/App.jsx React JSX
function App() {
    return (
        <div>
            <h1>Welcome to React!</h1>
            <p>My React application is running successfully.</p>
            <button>Explore Courses</button>
        </div>
    );
}

export default App;

Save the file. Vite normally detects source changes and refreshes the page or applies the update using Hot Module Replacement (HMR).

Expected Browser Output

Example Output

Welcome to React!

My React application is running successfully.

Explore Courses
Remember: The button in this example is only a visual element. It does not perform an action because no click handler has been added.

9. What Is Hot Module Replacement?

Hot Module Replacement (HMR) is a development feature used by Vite to apply supported code changes without requiring a full manual page reload in many cases.

✏️

Edit Code

Change a React component.

→
⚡

Vite Detects Changes

Processes the updated module.

→
🖥️

UI Updates

Applies supported changes in the browser.

Note: Some changes, errors, or configuration updates may still require a full page reload or restarting the development server.

10. How to Stop the Development Server

When you finish testing or need to stop the running server, switch to the terminal where npm run dev is running.

Ctrl
+
C

Press Ctrl + C in that terminal. If prompted to terminate the process, respond to the prompt as needed.

11. Common Errors and Solutions

Problem Possible Cause Solution
Missing script: dev The current project does not define a dev script, or the wrong folder is open. Check the current directory and the scripts in package.json.
vite is not recognized Dependencies may not be installed, or the project setup is incomplete. Run npm install in the project directory.
Port already in use Another process may already be using the default port. Check the terminal and open the alternate URL Vite provides.
Browser cannot connect The server may have stopped or the wrong URL was opened. Check the terminal and run npm run dev again if necessary.
Blank page There may be a compile error or a problem in the application code. Check the terminal, browser console, and React component code.
Changes are not visible The file may not have been saved, or an error may prevent the update. Save the file and check the terminal and browser console.

Debugging Tip

Check the terminal first for compilation and server errors. Then inspect the browser console if the application still does not behave as expected.

12. Development Server vs Production Build

The development server is intended for writing and testing code. Before deploying an application, you normally create a production build.

Development Production Build
Uses npm run dev. Uses npm run build in a typical Vite project.
Designed for coding and testing. Generates optimized assets for deployment.
Usually serves the app from localhost. Usually creates files in the dist directory.

Create a Production Build

Terminal Production
npm run build

Run this command when you are ready to check the production build. Deployment itself requires an appropriate hosting setup.

13. Practice Task

Task: Run and Modify Your React App

  1. Open your Vite React project in VS Code.
  2. Open a terminal in the project directory.
  3. Run npm install if dependencies are not installed.
  4. Execute npm run dev.
  5. Open the local URL displayed in the terminal.
  6. Update the heading in src/App.jsx.
  7. Save the file and check the updated browser output.
  8. Stop the development server with Ctrl + C.

Summary

  • Open the terminal in the correct project directory.
  • Run npm install if dependencies are missing.
  • Use npm run dev to start the Vite development server.
  • Open the URL displayed by Vite in the browser.
  • Update src/App.jsx to practise React development.
  • Vite can apply supported changes through HMR.
  • Use npm run build to create a production build in a typical Vite project.