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

Introduction to JSX

Learn how JSX makes it easier to describe user interfaces in React by combining JavaScript expressions with HTML-like syntax.

1. What Is JSX?

JSX stands for JavaScript XML. It is a syntax extension for JavaScript that allows developers to write HTML-like markup inside JavaScript code.

React developers commonly use JSX to describe what the user interface should look like. JSX is transformed into JavaScript instructions that React uses to create and update the UI.

JSX looks similar to HTML, but it follows some different rules. For example, React uses className instead of HTML's class attribute in JSX.

Remember: JSX is not HTML, and browsers do not directly execute JSX syntax. Development tools such as Vite transform JSX into JavaScript that the browser can execute.

2. How JSX Works

JSX is transformed during the build or development process before the browser executes the resulting JavaScript.

Step 1

JSX Code

<h1>Hello React!</h1>

Write markup inside JavaScript.

↓ Transformed by development tools
Step 2

JavaScript Transformation

Vite uses the project's configured tooling to process JSX into JavaScript.

↓ JavaScript executes
Step 3

React Elements

React uses the resulting JavaScript to describe the interface.

↓ React renders the UI
✓

Browser User Interface

The user sees the rendered heading or component.

Important: JSX transformation does not happen because the browser understands JSX natively. The development toolchain performs the transformation so the browser receives executable JavaScript.

3. Creating UI Without JSX

React can create UI elements without JSX by using createElement() from the React package.

App.jsx JavaScript
import { createElement } from 'react';

function App() {
    return createElement(
        'h1',
        null,
        'Hello React!'
    );
}

export default App;

Expected Output

Browser Output

Hello React!

This approach works, but creating deeply nested interfaces using repeated createElement() calls can make code difficult to read.

4. Creating UI With JSX

JSX allows us to write the same UI using a more readable, HTML-like structure.

App.jsx JSX
function App() {
    return <h1>Hello React!</h1>;
}

export default App;

Expected Output

Browser Output

Hello React!

Conclusion: Both examples describe the same heading. JSX makes the UI structure easier to read and maintain.

5. Understanding JSX Syntax

A JSX expression commonly contains an opening tag, some content, and a closing tag. JSX elements can also contain child elements and JavaScript expressions.

JSX Example Syntax
function App() {
    return (
        <div>
            <h1>Welcome to React</h1>
            <p>Learn React step by step.</p>
        </div>
    );
}

Breakdown of the Code

01

Opening Tag

<h1>

Starts the heading element.

02

Content

Welcome to React

Text displayed inside the heading.

03

Closing Tag

</h1>

Ends the heading element.

04

Parent Element

<div>

Groups the heading and paragraph.

6. Using JavaScript Expressions in JSX

We can insert JavaScript expressions into JSX by placing them inside curly braces { }.

App.jsx JSX Expressions
function App() {
    const studentName = 'Priya';
    const courseName = 'React Development';
    const duration = 5;

    return (
        <div>
            <h1>Welcome, {studentName}!</h1>
            <p>Course: {courseName}</p>
            <p>Duration: {duration} months</p>
            <p>Next level: {duration + 1} months</p>
        </div>
    );
}

export default App;

Expected Output

Browser Output

Welcome, Priya!

Course: React Development

Duration: 5 months

Next level: 6 months

Remember: Curly braces let JSX evaluate JavaScript expressions such as variables, arithmetic calculations, and function calls that return a value.

7. Difference Between JSX and HTML

Feature HTML JSX
CSS class attribute class className
Event handler onclick onClick
JavaScript expression Not directly embedded in ordinary HTML text this way Use { } inside JSX
Style attribute Normally written as a CSS string Uses a JavaScript object
Closing tags Depends on the HTML element JSX elements must be properly closed
Multiple root elements HTML document has a document structure A component must return one root element or a Fragment
Important: JSX is HTML-like, but it follows JavaScript and React rules. The browser ultimately works with the DOM created by React; JSX itself is a source-code syntax.

8. Common JSX Examples

Example 1: className Instead of class

App.jsx JSX
function App() {
    return (
        <div className="welcome-box">
            <h2>Welcome to CIIT</h2>
        </div>
    );
}

Use className to specify a CSS class in JSX.

Example 2: Event Handler Naming

App.jsx JSX
function App() {
    function handleClick() {
        console.log('Button clicked');
    }

    return (
        <button onClick={handleClick}>
            Click Me
        </button>
    );
}

JSX event handler names use camelCase, such as onClick. Here, handleClick is passed as a function rather than being called while rendering.

Example 3: Inline Styling

App.jsx JSX
function App() {
    return (
        <h2 style={{
            color: 'blue',
            fontSize: '28px'
        }}>
            React Styling
        </h2>
    );
}

In JSX, the style attribute receives a JavaScript object. CSS property names such as font-size are written in camelCase as fontSize.

9. Basic Rules of JSX

1

Return One Root Element

Wrap sibling elements inside a common parent element or use a Fragment.

2

Close Every Element

Use matching closing tags or self-closing syntax for elements that do not have children.

3

Use className for CSS Classes

JSX uses className instead of the HTML class attribute.

4

Use Curly Braces for Expressions

Insert JavaScript expressions inside JSX using { }.

5

Use CamelCase Event Names

Use names such as onClick and onChange for React event handlers.

10. Practice Task

Task: Create a Student Introduction Component

Create an App component that displays a student's name, course, and training duration.

  1. Create a variable named studentName.
  2. Create a variable named courseName.
  3. Create a variable named duration.
  4. Display their values using JSX curly braces.
  5. Add a CSS class using className.
  6. Run the application and verify the browser output.

Summary

  • JSX stands for JavaScript XML.
  • JSX lets developers write HTML-like markup inside JavaScript.
  • Development tooling transforms JSX into executable JavaScript.
  • Curly braces allow JavaScript expressions inside JSX.
  • Use className rather than HTML's class.
  • JSX elements must be properly closed and grouped under one root or a Fragment.
  • React components commonly use JSX to describe their UI.