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

React Fragments

Learn how React Fragments let you group multiple elements without adding an unnecessary DOM element.

1. What Are React Fragments?

A React component can return multiple sibling elements by wrapping them in a Fragment. A Fragment groups elements without introducing an extra DOM node.

Remember: Use a Fragment when you want to return multiple sibling elements without wrapping them in an additional div.
FragmentsExample.jsx JSX
function App() {
    return (
        <React.Fragment>
            <h2>Welcome to CIIT Training Institute</h2>
            <p>Learn React step by step.</p>
        </React.Fragment>
    );
}

export default App;

2. React Fragment Diagram

Compare a normal wrapper element with a Fragment. The Fragment groups its children without creating another DOM element.

Without Fragment

div
h2
p

The wrapper creates an additional DOM element.

With Fragment

Fragment (no DOM node)
h2
p

Only the child elements appear in the DOM.

3. Using React.Fragment

The full React.Fragment syntax groups sibling elements. In this example, React is imported so the React namespace is available.

FullFragment.jsx JSX
import React from "react";

function App() {
    return (
        <React.Fragment>
            <h2>Our Courses</h2>
            <p>Java Full Stack</p>
            <p>.NET Full Stack</p>
        </React.Fragment>
    );
}

export default App;

Expected Browser Output

Illustrative Browser Output

Our Courses

Java Full Stack

.NET Full Stack

4. Short Fragment Syntax

React also supports the shorter syntax <> ... </>. It is a convenient way to group sibling elements.

ShortFragment.jsx JSX
function App() {
    return (
        <>
            <h2>Student Details</h2>
            <p>Name: Priya</p>
            <p>Course: React JS</p>
        </>
    );
}

export default App;
Important: The short syntax cannot accept a key attribute. When rendering Fragment elements in a list and a key is needed, use the full React.Fragment syntax.

5. Fragments in Lists

When one list item needs to produce multiple sibling elements, a keyed Fragment can group them without adding a wrapper to the DOM.

FragmentList.jsx JSX
import React from "react";

function App() {
    const students = [
        { id: 1, name: "Priya", course: "React JS" },
        { id: 2, name: "Rahul", course: ".NET Full Stack" },
        { id: 3, name: "Amit", course: "Python" }
    ];

    return (
        <dl>
            {students.map((student) => (
                <React.Fragment key={student.id}>
                    <dt>{student.name}</dt>
                    <dd>{student.course}</dd>
                </React.Fragment>
            ))}
        </dl>
    );
}

export default App;

Expected Browser Output

Illustrative Browser Output
Priya
React JS
Rahul
.NET Full Stack
Amit
Python

6. React Fragment vs div

Feature React Fragment div Element
Creates a DOM element No Yes
Groups sibling elements Yes Yes
Can have CSS classes No Yes
Can have a key Full syntax only Yes
Useful for styling a wrapper No Yes
Use a div when a real wrapper is needed for layout, styling, or attributes. Use a Fragment when you only need to group elements.

7. Common Mistakes

1. Incorrect Fragment closing syntax

Incorrect:

<>Hello</React.Fragment>

Correct:

<>Hello</>

2. Adding a className to a Fragment

Fragments do not support regular DOM attributes such as className. Use a real element if you need styling on a wrapper.

3. Using short syntax when a key is required

Use React.Fragment with a stable key when grouping multiple elements inside a mapped list.

8. Practice Questions

  1. Return a heading and two paragraphs using short Fragment syntax.
  2. Rewrite a component that uses a wrapper div by using a Fragment.
  3. Create a student list using keyed Fragments.
  4. Explain when a div is more appropriate than a Fragment.
  5. Identify why a Fragment cannot receive a className.

Summary

React Fragments allow you to group multiple JSX elements without adding an extra DOM node. You can use the short syntax <>...</> for simple grouping or React.Fragment when you need to provide a key. Fragments help keep your component structure clean while rendering headings, paragraphs, and other sibling elements.