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

Props Introduction in React

Learn how React components receive data through props and display reusable content at CIIT Training Institute.

Beginner Friendly Practical Examples Expected Output Included

01 Learning Objectives

After completing this lesson, you will be able to:

01
Understand Props

Learn how props pass data to components.

02
Reuse Components

Display different information with the same component.

03
Pass Different Values

Pass strings, numbers and other supported values.

04
Follow Props Rules

Understand why props should be treated as read-only.

02 What Are Props?

Props means properties. They allow a parent component to pass data to a child component. The child component receives this data and uses it to display dynamic content.

Remember: Props are read-only inputs. A child component should not directly modify the props it receives. When data needs to change, the parent can pass updated values or provide a callback.
Welcome.jsx JSX
function Welcome(props) {
    return <h2>Welcome, {props.name}!</h2>;
}

export default Welcome;
App.jsx JSX
import Welcome from "./Welcome";

function App() {
    return (
        <div>
            <Welcome name="Samadhan" />
        </div>
    );
}

export default App;
Expected Browser Output

Welcome, Samadhan!

03 How Props Work

The parent component supplies values through JSX attributes. React makes those values available to the child component through its props parameter.

PARENT COMPONENT App name="Samiksha"
↓
Passes props
↓
CHILD COMPONENT Welcome props.name
↓
RENDERED UI Welcome, Samiksha!
App.jsx JSX
function Welcome(props) {
    return <h2>Welcome, {props.name}!</h2>;
}

function App() {
    return <Welcome name="Samiksha" />;
}

export default App;
Expected Browser Output

Welcome, Samiksha!

The value of the name prop is displayed by Welcome.

04 Passing String Props

String values can be passed through JSX attributes using quotation marks. The same component can display different messages depending on the value it receives.

Greeting.jsx JSX
function Greeting(props) {
    return <p>Hello, {props.name}!</p>;
}

export default Greeting;
App.jsx JSX
import Greeting from "./Greeting";

function App() {
    return (
        <section>
            <h2>CIIT Student Greetings</h2>
            <Greeting name="Samadhan" />
            <Greeting name="Samiksha" />
            <Greeting name="Pradnya" />
        </section>
    );
}

export default App;
Expected Browser Output

CIIT Student Greetings

Hello, Samadhan!

Hello, Samiksha!

Hello, Pradnya!

05 Passing Number Props

To pass a number or another JavaScript expression, use curly braces in JSX. Without curly braces, a value written inside quotation marks is treated as a string.

Student.jsx JSX
function Student(props) {
    return (
        <div>
            <h3>{props.name}</h3>
            <p>Marks: {props.marks}</p>
            <p>Next Test Marks: {props.marks + 5}</p>
        </div>
    );
}

export default Student;
App.jsx JSX
import Student from "./Student";

function App() {
    return (
        <Student name="Pradnya" marks={80} />
    );
}

export default App;
Expected Browser Output

Pradnya

Marks: 80

Next Test Marks: 85

Important: marks={80} passes the number 80, whereas marks="80" passes the string "80".

06 Passing Multiple Props

A component can receive multiple props at the same time. For example, a course card can receive a course name, duration and training mode.

CourseCard.jsx JSX
function CourseCard(props) {
    return (
        <div>
            <h3>{props.courseName}</h3>
            <p>Duration: {props.duration}</p>
            <p>Mode: {props.mode}</p>
        </div>
    );
}

export default CourseCard;
App.jsx JSX
import CourseCard from "./CourseCard";

function App() {
    return (
        <CourseCard
            courseName="React JS"
            duration="3 Months"
            mode="Online and Offline"
        />
    );
}

export default App;
Expected Browser Output

React JS

Duration: 3 Months

Mode: Online and Offline

07 Reusing Components with Different Props

One reusable component can render multiple cards with different data. The component structure remains the same, while its props determine the content displayed.

CourseCard.jsx JSX
function CourseCard(props) {
    return (
        <div>
            <h3>{props.title}</h3>
            <p>Technology: {props.technology}</p>
        </div>
    );
}

export default CourseCard;
App.jsx JSX
import CourseCard from "./CourseCard";

function App() {
    return (
        <section>
            <h2>CIIT Training Courses</h2>

            <CourseCard
                title="React Development"
                technology="React JS"
            />

            <CourseCard
                title=".NET Full Stack"
                technology="ASP.NET Core"
            />

            <CourseCard
                title="Python Development"
                technology="Python"
            />
        </section>
    );
}

export default App;
Expected Browser Output

CIIT Training Courses

React Development Technology: React JS
.NET Full Stack Technology: ASP.NET Core
Python Development Technology: Python

08 Props Are Read-Only

Props should be treated as read-only inputs. A component must not assign a new value directly to a prop. To change displayed information, the parent can pass new props or use state and event handlers.

Welcome.jsx JSX
function Welcome(props) {
    // Read the prop; do not modify it.
    return <h2>Welcome, {props.name}!</h2>;
}

export default Welcome;
Avoid this pattern: Do not write props.name = "Another Name" inside the component. Instead, update the value in the parent and pass the new value down.
Expected Browser Output

Welcome, Samadhan!

The component displays the value provided by its parent.

09 Common Props Mistakes

1. Missing Props Parameter

If a component needs a prop, receive it through the component parameter.

function Welcome(props) { ... }

2. Incorrect JavaScript Value Syntax

Use curly braces when passing a number or JavaScript expression.

<Student marks={80} />

3. Wrong Prop Name

The name used by the child must match the attribute passed by the parent.

<Welcome name="Samiksha" />

4. Modifying Props

Treat props as read-only. Use parent updates or state for changing data.

return <p>{props.name}</p>;

10 Practice Questions

  1. What are props in React?
  2. How does a parent component pass props to a child?
  3. Pass a name prop to a Welcome component.
  4. Create a Student component that receives name and marks.
  5. Build a CourseCard that receives course name and duration.
  6. Display Samadhan, Samiksha and Pradnya using one reusable component.
  7. Why should props be treated as read-only?

Summary

Props are inputs that allow parent components to pass data to child components. They can contain strings, numbers and other JavaScript values. A reusable component can display different content depending on the props it receives. Props should be treated as read-only, and component reuse helps keep applications organized and maintainable at CIIT Training Institute.