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

JSX vs HTML

Understand the differences between HTML and JSX, including attributes, JavaScript expressions, event handlers, inline styles, and element structure.

1. What Is the Difference Between JSX and HTML?

HTML is a markup language used to structure web pages. JSX is a JavaScript syntax extension commonly used with React to describe user interfaces.

JSX looks similar to HTML, but some attribute names, syntax rules, and JavaScript integration features are different.

Feature HTML JSX
CSS class attribute class className
Label association for htmlFor
JavaScript expressions Require appropriate script context Use curly braces in JSX
Event handler example onclick onClick
Inline styles CSS string JavaScript object
Multiple sibling elements Allowed in document structure Group them when returning JSX from a component

2. class vs className

In HTML, use class to apply CSS classes. In JSX, use className.

HTML Example

HTML
<div class="student-card">
    <h2>Samadhan</h2>
    <p>Learning HTML</p>
</div>
Expected Output

Samadhan

Learning HTML

JSX Example

JSX
function App() {
    return (
        <div className="student-card">
            <h2>Samadhan</h2>
            <p>Learning React</p>
        </div>
    );
}

export default App;
Expected Output

Samadhan

Learning React

Key Point: HTML uses class, while JSX uses className for CSS classes.

3. for vs htmlFor

HTML labels use the for attribute to associate a label with a form field. JSX uses htmlFor.

LabelExample.jsx JSX
function App() {
    return (
        <div>
            <h2>Student Registration</h2>

            <label htmlFor="studentName">
                Student Name:
            </label>

            <input
                id="studentName"
                type="text"
                defaultValue="Samiksha"
            />
        </div>
    );
}

export default App;

Expected Output

Browser Preview

Student Registration

4. JavaScript Expressions in JSX

JSX allows JavaScript expressions inside curly braces. You can display variables, perform calculations, and generate dynamic content.

StudentMarks.jsx JSX
function App() {
    const studentName = "Pradnya";
    const subject1 = 85;
    const subject2 = 90;
    const total = subject1 + subject2;

    return (
        <div>
            <h2>Student Result</h2>
            <p>Name: {studentName}</p>
            <p>Subject 1: {subject1}</p>
            <p>Subject 2: {subject2}</p>
            <p>Total Marks: {total}</p>
        </div>
    );
}

export default App;

Expected Output

Browser Preview

Student Result

Name: Pradnya

Subject 1: 85

Subject 2: 90

Total Marks: 175

Key Point: Curly braces allow JavaScript expressions inside JSX. Plain HTML does not interpret JSX curly braces as JavaScript expressions.

5. Event Handlers: HTML vs JSX

JSX uses camelCase event names such as onClick and expects a function as the handler.

ClickExample.jsx JSX
function App() {
    function handleClick() {
        alert("Welcome, Samadhan!");
    }

    return (
        <div>
            <h2>Event Handling
            <button onClick={handleClick}>
                Click Me
            </button>
        </div>
    );
}

export default App;

Expected Output

Interactive Browser Preview
{@body const [showWelcome, setShowWelcome] = DIL.useState(false)}

Event Handling

{#if showWelcome}

Welcome, Samadhan!

{/if}

The preview button demonstrates the expected result. The React program above is the code students should write in their React application.

6. Inline Styles in HTML and JSX

HTML accepts CSS declarations as a string in the style attribute. JSX uses a JavaScript object with camelCase property names.

HTML

HTML
<h2 style="color: blue;
background-color: lightyellow;">
    Samiksha
</h2>

JSX

JSX
function App() {
    return (
        <h2 style={{
            color: "blue",
            backgroundColor: "lightyellow"
        }}>
            Samiksha
        </h2>
    );
}

export default App;

Expected Output

Browser Preview

Samiksha

7. Self-Closing Tags

In JSX, elements such as img and input must be self-closed when written without a closing tag.

SelfClosing.jsx JSX
function App() {
    return (
        <div>
            <h2>Student Profile</h2>
            <input type="text" placeholder="Enter name" />
            <img src="/images/student.png"
                 alt="Student profile" />
        </div>
    );
}

export default App;

Expected Output

Browser Preview

Student Profile

An image appears when a valid image asset is available at the specified path.

8. Conditional Rendering in JSX

JSX supports JavaScript conditional expressions such as the ternary operator. They can display different content based on a condition.

ConditionalExample.jsx JSX
function App() {
    const isCompleted = true;

    return (
        <div>
            <h2>Course Status</h2>

            <p>
                {isCompleted
                    ? "Samadhan completed the course."
                    : "Samadhan is still learning."}
            </p>
        </div>
    );
}

export default App;

Expected Output

Browser Preview

Course Status

Samadhan completed the course.

9. Common Mistakes

1. Using class instead of className

Incorrect JSX:

<div class="card">Hello</div>

Correct JSX:

<div className="card">Hello</div>

2. Forgetting to close an element

Incorrect JSX:

<input type="text">

Correct JSX:

<input type="text" />

3. Using an incorrect event handler

Incorrect JSX:

onclick={handleClick}

Correct JSX:

onClick={handleClick}

4. Forgetting keys in rendered lists

When rendering an array of elements, provide a stable key such as student.id to each sibling element returned by the list mapping.

10. Practice Questions

  1. Explain three differences between HTML and JSX.
  2. Write a JSX component that displays Samadhan's name using a JavaScript variable.
  3. Create a student registration form using className and htmlFor.
  4. Create a button using the onClick event handler.
  5. Display Samiksha's course completion status using a ternary expression.
  6. Render Samadhan, Samiksha, and Pradnya in a list using stable keys.
  7. Write a JSX heading with inline styles using a JavaScript object.

Summary

JSX is a JavaScript syntax extension used to describe React user interfaces. Unlike HTML, JSX uses className for CSS classes, htmlFor for label associations, curly braces for JavaScript expressions, camelCase event handlers, and JavaScript objects for inline styles. JSX elements must follow valid syntax, and mapped list items should have stable keys. Understanding these differences helps you write clean and maintainable React applications.