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

Default Props Values

Learn how to provide fallback values to React components when optional props are not supplied by the parent component.

01 What Are Default Props Values?

Default props values are fallback values used when a component does not receive a particular prop value. They help prevent optional information from appearing empty in the UI.

Default Props Flow
Parent Component Passes props or leaves them out
↓
Prop Provided Use supplied value
Prop Missing Use fallback value
↓
Child Component Displays the resolved value
A default is generally used when a prop is omitted or its value is undefined. Passing null or an empty string does not automatically trigger the default.
Expected Browser Output

Samadhan

Guest

The first value can be supplied; the second can use a default.

02 Default Values Using Destructuring

A simple way to define defaults in a functional component is to assign fallback values while destructuring the props.

Student.jsx
function Student({ name = "Guest" }) {
    return <h2>Student Name: {name}</h2>;
}

export default Student;

When the parent renders <Student />, the default name is used.

Expected Browser Output

Student Name: Guest

03 Passing a Custom Value

When the parent supplies a value, React uses that value instead of the fallback value.

App.jsx
function App() {
    return <Student name="Samiksha" />;
}

function Student({ name = "Guest" }) {
    return <h2>Student Name: {name}</h2>;
}

export default App;
Provided Value Wins
App name="Samiksha"
↓
Student Receives Samiksha
↓
Default "Guest" is not used
Expected Browser Output

Student Name: Samiksha

04 Multiple Default Props

You can assign default values to multiple props in the same component, such as name, course and city.

Student.jsx
function Student({
    name = "Guest",
    course = "Not Assigned",
    city = "Pune"
}) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Course: {course}</p>
            <p>City: {city}</p>
        </div>
    );
}

export default Student;
Expected Browser Output

Guest

Course: Not Assigned

City: Pune

05 Mixing Provided and Default Values

A parent can provide some props and leave others unspecified. Only the missing or undefined props use their defaults.

App.jsx
function App() {
    return (
        <Student
            name="Pradnya"
            course="Python"
        />
    );
}

function Student({
    name = "Guest",
    course = "Not Assigned",
    city = "Pune"
}) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Course: {course}</p>
            <p>City: {city}</p>
        </div>
    );
}

export default App;
Expected Browser Output

Pradnya

Course: Python

City: Pune

06 Default Values for Numbers

Defaults also work with numbers. Use a numeric value directly rather than writing it as a string.

Student.jsx
function Student({ name = "Guest", age = 18 }) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Age: {age}</p>
        </div>
    );
}

export default Student;
Expected Browser Output

Guest

Age: 18

07 Default Values for Arrays

An array can also have a default value. Here, an empty array is used when the parent does not provide a skills prop.

Student.jsx
function Student({
    name = "Guest",
    skills = []
}) {
    return (
        <div>
            <h2>{name}</h2>
            <h3>Skills
        
Expected Browser Output

Guest

Skills

No skills added yet.

08 Default Values with Reusable Components

Default props are helpful in reusable components because the component can still display meaningful content when optional information is not supplied.

App.jsx
function App() {
    return (
        <div>
            <Course name="React JS" duration="3 Months" />
            <Course name=".NET" />
            <Course />
        </div>
    );
}

function Course({
    name = "General Course",
    duration = "Duration not specified"
}) {
    return (
        <div>
            <h3>{name}</h3>
            <p>Duration: {duration}</p>
        </div>
    );
}

export default App;
Same Component, Different Defaults
App Renders Course three times
↓
Course React JS 3 Months
Course .NET Duration not specified
Course General Course Duration not specified
Expected Browser Output

React JS

Duration: 3 Months


.NET

Duration: Duration not specified


General Course

Duration: Duration not specified

09 Default Value vs Null and Empty String

A destructuring default is used when a prop is undefined. It does not replace null or an empty string automatically.

App.jsx
function App() {
    return (
        <div>
            <Student />
            <Student name={null} />
            <Student name="" />
        </div>
    );
}

function Student({ name = "Guest" }) {
    return (
        <p>
            Name: {name === null
                ? "null"
                : name === ""
                    ? "empty string"
                    : name}
        </p>
    );
}

export default App;
Expected Browser Output

Name: Guest

Name: null

Name: empty string

10 Important Rules for Default Props

  • Defaults provide fallback values for omitted or undefined props.
  • A value explicitly provided by the parent takes precedence.
  • Defaults can be declared during parameter destructuring.
  • Defaults can be used for strings, numbers, arrays and objects.
  • Passing null does not trigger a destructuring default.
  • Default values do not make props mutable.
Expected Browser Output

This section explains the rules for default values. It does not render a separate React component.

Summary

Default props values provide fallback content when optional props are omitted or undefined. In functional components, defaults can be assigned directly during parameter destructuring. The parent component's supplied values take precedence over defaults, while null and empty strings remain distinct values. Default values make reusable components more reliable, readable and easier to maintain in React applications at CIIT Training Institute.