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 vs State in React

Learn the difference between Props and State in React, how they work, and when to use each one in your components.

1. Introduction to Props vs State

Props and State are important concepts in React. Both help components work with data, but they have different purposes.

  • Props: Data passed from a parent component to a child component.
  • State: Data managed inside a component that can change over time.
// Props
<Student name="Samadhan" />

// State
const [count, setCount] = useState(0);
Expected Browser Output

Props example: Samadhan

State example: Count = 0

2. What Are Props?

Props, short for properties, allow a parent component to send data to a child component. A child component should treat props as read-only and should not modify them directly.

function Student(props) {
    return <h2>Student Name: {props.name}</h2>;
}

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

export default App;
Expected Browser Output

Student Name: Samiksha

3. What Is State?

State is data managed within a component. When state changes using its setter function, React can render the component again to display the updated value.

import { useState } from "react";

function Counter() {
    const [count, setCount] = useState(0);

    return (
        <div>
            <h2>Count: {count}</h2>
            <button onClick={() => setCount(count + 1)}>
                Increase
            </button>
        </div>
    );
}

export default Counter;
Expected Browser Output

Initially: Count: 0

After one click on Increase: Count: 1

After two clicks on Increase: Count: 2

4. Difference Between Props and State

The following table highlights the main differences between Props and State.

Props State
Passed from a parent component. Managed within a component.
Read-only for the receiving component. Updated using a state setter such as setCount.
Used to configure or provide data to a component. Used to store changing component data.
Can change when the parent supplies different values. Can change in response to user actions or other logic.
Example: student name. Example: counter value.
Expected Browser Output

Props: Student Name = Pradnya

State: Counter Value = 0

After updating the counter: Counter Value = 1

5. Example of Props and State Together

A component can receive a student's name through props and maintain a separate counter using state.

import { useState } from "react";

function StudentCard({ name }) {
    const [likes, setLikes] = useState(0);

    return (
        <div>
            <h2>Student: {name}</h2>
            <p>Likes: {likes}</p>
            <button onClick={() => setLikes(likes + 1)}>
                Like
            </button>
        </div>
    );
}

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

export default App;
Expected Browser Output

Student: Samadhan

Likes: 0

After clicking Like once: Likes: 1

6. Can Props Change?

A child component must not directly modify its props. However, the parent can provide a different prop value when its own data changes. The child then receives the new value.

function Student({ name }) {
    return <h2>Student: {name}</h2>;
}

function App() {
    const studentName = "Samiksha";

    return <Student name={studentName} />;
}

export default App;
Expected Browser Output

Student: Samiksha

The Student component displays the value received through props.

7. How State Changes

Use the state setter to update state. React then renders the component with the new value. Do not directly modify state variables.

import { useState } from "react";

function StudentStatus() {
    const [status, setStatus] = useState("Learning");

    return (
        <div>
            <p>Status: {status}</p>
            <button onClick={() => setStatus("Completed")}>
                Complete Course
            </button>
        </div>
    );
}

export default StudentStatus;
Expected Browser Output

Initially: Status: Learning

After clicking Complete Course: Status: Completed

8. When Should You Use Props or State?

Use Props when:

  • A parent needs to pass data to a child component.
  • You want a reusable component with configurable values.
  • You need to pass a callback function from a parent to a child.

Use State when:

  • A component needs to remember a changing value.
  • You need to handle input values, counters, or toggles.
  • The displayed UI should respond to changes in component data.
// Props: configure the component
<Student name="Pradnya" />

// State: manage a changing value
const [isVisible, setIsVisible] = useState(true);
Expected Browser Output

Props example: Student Name = Pradnya

State example: isVisible = true

When isVisible becomes false, conditional UI can be hidden.

9. Common Mistakes

  • Trying to change props directly inside a child component.
  • Changing state variables directly instead of using the setter.
  • Using props when the component needs to manage its own changing data.
  • Using state for values that can simply be calculated from existing props or state.
// Incorrect: do not modify props
function Student(props) {
    // props.name = "New Name"; // Avoid this
    return <p>{props.name}</p>;
}

// Correct: use a state setter
const [count, setCount] = useState(0);
setCount(count + 1);
Expected Browser Output

The Student component displays the provided prop.

The counter updates through its state setter.

10. Quick Revision

Props pass data into components, while state stores data that a component manages and updates. Both can influence what React displays on the screen.

// Props
<Student name="Samadhan" />

// State
const [count, setCount] = useState(0);
Expected Browser Output

Student Name: Samadhan

Initial Count: 0

Summary

Props are used to pass data from a parent component to a child component, and the receiving component should treat that data as read-only. State is managed within a component and can be updated with a state setter, allowing React to render the updated UI. Use props to configure reusable components and state to manage changing data such as counters, form inputs, and visibility. Understanding both concepts is essential for building interactive React applications.