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

Your First React Application

Build your first React application using components, JSX, props, CSS styling, and reusable UI elements.

1. Introduction

React is a JavaScript library used to build user interfaces. A React application is generally created by combining reusable components that describe different parts of the screen.

In this lesson, we will create a simple training institute application with a heading, course cards, and a footer. We will also learn how the application is rendered in the browser.

Our goal: Create a React page that displays a training institute name, three courses, and a short message using reusable components.

2. First React Application Flow

Entry Point

main.jsx

Starts the React application

↓
Root Component

App.jsx

Combines the application's components

↓

Header

Institute name

CourseCard

Course information

Footer

Closing message

↓

Browser UI

The rendered React application

3. Before You Start

✓

React Project

A Vite React project should already be created.

✓

Dependencies

Project dependencies should be installed with npm.

✓

Code Editor

Use VS Code or another suitable code editor.

✓

Development Server

Run the project with npm run dev.

4. Step 1: Understand the Project Files

We will mainly work with these files in the src folder.

📁 src
📄 main.jsx Application entry point
📄 App.jsx Main application component
📄 App.css Application styles
📄 index.css Global styles
Important: Your Vite template may contain additional files. For this lesson, we will use App.jsx and App.css for the main example.

5. Step 2: Create the App Component

Open src/App.jsx. Replace its contents with the following complete example.

src/App.jsx React JSX
import './App.css';

function Header() {
    return (
        <header className="app-header">
            <h1>CIIT Training Institute</h1>
            <p>Learn. Practice. Grow.</p>
        </header>
    );
}

function CourseCard({ title, description }) {
    return (
        <article className="course-card">
            <h3>{title}</h3>
            <p>{description}</p>
            <button type="button">Explore Course</button>
        </article>
    );
}

function CourseList() {
    return (
        <section className="course-section">
            <h2>Our Popular Courses</h2>

            <div className="course-grid">
                <CourseCard
                    title="Java Full Stack"
                    description="Learn Java, SQL, APIs, and web development."
                />

                <CourseCard
                    title="Python Full Stack"
                    description="Learn Python, databases, and web development."
                />

                <CourseCard
                    title="React Development"
                    description="Build modern user interfaces using React."
                />
            </div>
        </section>
    );
}

function Footer() {
    return (
        <footer className="app-footer">
            <p>Start learning today and build your future.</p>
        </footer>
    );
}

function App() {
    return (
        <div className="training-app">
            <Header />
            <main>
                <CourseList />
            </main>
            <Footer />
        </div>
    );
}

export default App;
What did we create? Header, CourseCard, CourseList, and Footer are components. The App component combines them to create the complete page.

6. Step 3: Add CSS Styling

Open src/App.css and replace its contents with the following CSS.

src/App.css CSS
.training-app {
    min-height: 100vh;
    color: #1e293b;
    background: #f8fafc;
    font-family: Arial, sans-serif;
}

.app-header {
    padding: 38px 20px;
    text-align: center;
    color: white;
    background: linear-gradient(135deg, #4338ca, #2563eb);
}

.app-header h1 {
    margin: 0 0 10px;
    font-size: 2rem;
}

.app-header p {
    margin: 0;
    color: #e0e7ff;
}

.course-section {
    max-width: 1100px;
    margin: 0 auto;
    padding: 35px 20px;
}

.course-section h2 {
    margin-bottom: 24px;
    text-align: center;
}

.course-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.course-card {
    padding: 22px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.course-card h3 {
    margin-top: 0;
    color: #3730a3;
}

.course-card p {
    line-height: 1.7;
    color: #64748b;
}

.course-card button {
    padding: 10px 14px;
    color: white;
    background: #4338ca;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
}

.app-footer {
    padding: 20px;
    text-align: center;
    background: #e2e8f0;
}

.app-footer p {
    margin: 0;
    color: #334155;
}

@media (max-width: 767px) {
    .course-grid {
        grid-template-columns: 1fr;
    }

    .app-header h1 {
        font-size: 1.6rem;
    }
}
CSS tip: In a Razor .cshtml page, CSS at-rules use @media so Razor outputs a single @media in the rendered stylesheet. In your React file App.css, write normal CSS as @media, with only one @.

7. Step 4: Understand the Component Structure

React allows us to separate the application into smaller components. In this example, the component structure looks like this:

App

Root component

Header

Page heading

CourseList

Course section

CourseCard × 3

Footer

Bottom message

App

Combines the main components into one application.

Header

Displays the institute name and introductory text.

CourseList

Groups the course cards into a single section.

CourseCard

Displays individual course information through props.

Footer

Displays the closing message.

8. Step 5: Understand Props

Props are values passed from a parent component to a child component. We use props to display different course information without writing a separate component for every course.

CourseCard.jsx — Concept Example JSX
function CourseCard({ title, description }) {
    return (
        <article>
            <h3>{title}</h3>
            <p>{description}</p>
        </article>
    );
}

Passing Different Props

Inside CourseList JSX
<CourseCard
    title="Java Full Stack"
    description="Learn Java and web development."
/>

<CourseCard
    title="React Development"
    description="Learn to build React interfaces."
/>

Expected Results

Java Full Stack

Learn Java and web development.

React Development

Learn to build React interfaces.

9. Step 6: Run the Application

Save both App.jsx and App.css. Open your terminal in the React project directory and run:

Terminal npm
npm run dev

If the development server is already running, you can normally leave it running while you edit the files.

1

Save the Files

Save App.jsx and App.css.

2

Check the Terminal

Resolve compilation errors if any are displayed.

3

Open the Browser

Visit the local URL shown by Vite.

4

Check the Result

Verify the heading, course cards, buttons, and footer.

10. Expected Browser Output

After the code compiles successfully, the page should display a heading, three course cards, and a footer message.

React Application Preview

CIIT Training Institute

Learn. Practice. Grow.

Our Popular Courses

Java Full Stack

Learn Java, SQL, APIs, and web development.

Explore Course

Python Full Stack

Learn Python, databases, and web development.

Explore Course

React Development

Build modern user interfaces using React.

Explore Course

This is a static illustration of the expected appearance. It is not a live React application or a preview of your running project.

11. React Concepts Used in This Application

Concept Where It Is Used Purpose
Components Header, CourseCard, CourseList, Footer Breaks the UI into reusable parts.
JSX Return statements Describes the component's UI.
Props CourseCard Passes course titles and descriptions.
CSS App.css Controls colors, spacing, cards, and layout.
Composition App uses Header, CourseList, and Footer Combines components to form a larger UI.

12. Common Errors and Solutions

Problem Possible Cause Solution
CSS is not applied CSS file is not imported or the class names differ. Check import './App.css' and class names.
Blank browser page Compilation error or incorrect component export. Check the terminal and browser console.
Component is not displayed The component is not used in the returned JSX. Check the component tree inside App.
Props are undefined A prop is missing or its name does not match. Compare the prop names passed by the parent and read by the child.
JSX syntax error Missing closing tags, parentheses, or braces. Check the JSX structure and the terminal error.

Debugging Tip

Read the terminal error first. React and Vite usually provide helpful details about syntax errors, missing imports, or invalid component code.

13. Practice Task

Task: Customize Your First React Application

  1. Replace the default content of App.jsx.
  2. Create Header, CourseCard, CourseList, and Footer components.
  3. Display at least three different courses.
  4. Pass each course title and description through props.
  5. Style the page using App.css.
  6. Make sure the layout works on smaller screens.
  7. Run the application using npm run dev.
  8. Change one course title and verify the updated browser output.

Summary

  • A React application can be built using reusable components.
  • App.jsx combines the main parts of the UI.
  • JSX describes the content returned by components.
  • Props provide different information to reusable components.
  • App.css controls the application's appearance.
  • npm run dev starts the Vite development server in a typical Vite project.
  • Terminal messages help identify compilation errors.