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

What Is JSX?

Understand JSX, why React developers use it, how it works with JavaScript, and how to write JSX in a React component.

1. What Is JSX?

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

React developers commonly write JSX inside components. It makes UI code easier to read because the structure of the interface appears close to the JavaScript logic that defines it.

Definition: JSX is a JavaScript syntax extension used to describe the structure of user interfaces in React.

2. Why Do We Use JSX?

Without JSX, UI elements can be created using createElement(). For complex interfaces, that approach can become difficult to read. JSX provides a clearer way to organize UI elements.

Aa

Readable Code

The component's markup is easy to read and understand.

</>

Clear Structure

Parent and child elements are visible in the code.

{ }

JavaScript Expressions

Variables and calculations can be inserted into JSX.

UI

Component-Based UI

JSX can be returned from reusable React components.

3. How JSX Connects with React

JSX describes the interface, JavaScript provides the logic, and React uses the resulting element descriptions to render the user interface.

Component

JavaScript Function

A component returns JSX.

↓ Returns
UI Description

JSX

<h1>Hello React!</h1>
↓ Transformed by development tooling
Transformation

JavaScript

JSX is transformed into executable JavaScript.

↓ React renders the result
✓

Browser UI

The user sees Hello React!

Remember: JSX is not a separate programming language. It is an extension of JavaScript syntax, and the configured development tools transform it before the browser executes the code.

4. First JSX Example

The following React component returns a heading written in JSX.

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

export default App;

Code Explanation

function App()

Defines a React function component.

return

Returns the UI description from the component.

<h1>Hello React!</h1>

JSX describing the heading to display.

export default App

Allows other files to import this component.

Expected Browser Output

Example Output

Hello React!

5. JSX Looks Similar to HTML

JSX uses tags similar to HTML tags. You can use headings, paragraphs, lists, buttons, and other elements to describe your UI.

App.jsx JSX
function App() {
    return (
        <div>
            <h1>CIIT Training Institute</h1>
            <p>Learn software development.</p>

            <ul>
                <li>Java Full Stack</li>
                <li>Python Full Stack</li>
                <li>React Development</li>
            </ul>
        </div>
    );
}

export default App;

Expected Output

Example Output

CIIT Training Institute

Learn software development.

  • Java Full Stack
  • Python Full Stack
  • React Development
Important: JSX syntax is similar to HTML, but JSX follows its own rules. For example, CSS classes are specified with className, and elements must be properly closed.

6. JSX Can Use JavaScript Expressions

Curly braces { } let you place JavaScript expressions inside JSX. This is useful when you want to display data stored in variables or calculate a value.

App.jsx JSX + JavaScript
function App() {
    const studentName = 'Priya';
    const courseName = 'React Development';
    const totalMonths = 5;

    return (
        <div>
            <h1>Welcome, {studentName}!</h1>
            <p>Course: {courseName}</p>
            <p>Duration: {totalMonths} months</p>
            <p>Remaining example value: {totalMonths - 2}</p>
        </div>
    );
}

export default App;

Expected Output

Example Output

Welcome, Priya!

Course: React Development

Duration: 5 months

Remaining example value: 3

Remember: Curly braces evaluate JavaScript expressions. For example, {totalMonths - 2} produces the number 3.

7. JSX vs HTML

Although JSX looks like HTML, it is used inside JavaScript and has some different syntax rules.

Feature HTML JSX
CSS classes class="card" className="card"
Click event onclick onClick
JavaScript variables Not inserted into regular HTML text using JSX syntax {'{' }variable{' }'}
Inline styles Normally use a CSS string Use a JavaScript style object
Self-closing element Some HTML elements do not require a closing tag Write self-closing JSX elements with a slash, such as <img />
Component output HTML forms part of a document A component returns JSX or another supported React node

8. JSX and JavaScript Relationship

JSX is written as part of JavaScript source code. You can define variables and functions, then use their values within JSX to create dynamic interfaces.

App.jsx JSX
function App() {
    const courseCount = 3;

    function getWelcomeMessage() {
        return 'Welcome to React learning!';
    }

    return (
        <div>
            <h1>{getWelcomeMessage()}</h1>
            <p>Available courses: {courseCount}</p>
        </div>
    );
}

export default App;

Expected Output

Example Output

Welcome to React learning!

Available courses: 3

Key Point: You can use a JavaScript expression inside JSX, such as a variable or function call. Statements such as a regular if statement cannot be placed directly inside JSX expression braces; use appropriate JavaScript logic outside the returned markup or conditional expressions instead.

9. Common JSX Mistakes

Mistake Correct Approach
Using class in JSX Use className for CSS classes.
Missing closing tags Close each element or use self-closing syntax.
Returning adjacent root elements without grouping Wrap them in one parent or a React Fragment.
Writing a variable name as ordinary JSX text Use curly braces to evaluate a variable.
Using lowercase for a custom component Use an uppercase component name, such as CourseCard.
Debugging Tip: If a JSX example does not compile, check the closing tags, braces, component names, imports, and the error displayed in the development terminal.

10. Practice Task

Task: Create a Student Information Component

Create an App component that displays information about a student using JSX.

  1. Create a variable called studentName.
  2. Create a variable called courseName.
  3. Create a variable called duration.
  4. Display all three values using curly braces.
  5. Add a heading and a paragraph for each value.
  6. Run the application and verify the browser output.

Summary

  • JSX stands for JavaScript XML.
  • It is a syntax extension for describing user interfaces.
  • JSX can be returned from React components.
  • JavaScript expressions can be used inside JSX curly braces.
  • JSX looks similar to HTML but follows different rules.
  • Development tooling transforms JSX into JavaScript.
  • Proper JSX syntax makes React code easier to maintain.