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

Context API vs Props

Understand the differences between Props and Context API and learn when to use each approach in React applications.

1. What Are Props?

Props are inputs passed from a parent component to a child component. They allow components to receive data and functions from their parent.

Props are useful when a parent needs to pass specific information to a child, such as a student name, course title, product price, or button callback.

Student.jsx
function Student(props) {
    return (
        <div>
            <h2>Student Name: {props.name}</h2>
            <p>Course: {props.course}</p>
        </div>
    );
}

export default Student;
App.jsx
import Student from './Student';

function App() {
    return (
        <Student
            name="Samadhan"
            course="React Development"
        />
    );
}

export default App;

Expected Output

Student Name: Samadhan

Course: React Development

Props are read-only inputs from the receiving component's perspective. If data changes, the parent should provide updated props.

2. What Is Context API?

Context API allows a component to read a value supplied by a matching Provider above it in the component tree. It reduces the need to pass the same value through intermediate components that do not need to use that value.

Context is useful for information shared by several components, such as the current theme, language preference, or logged-in user information.

ThemeContext.jsx
import { createContext } from 'react';

const ThemeContext = createContext('light');

export default ThemeContext;
App.jsx
import ThemeContext from './ThemeContext';
import ThemeDisplay from './ThemeDisplay';

function App() {
    return (
        <ThemeContext.Provider value="dark">
            <ThemeDisplay />
        </ThemeContext.Provider>
    );
}

export default App;
ThemeDisplay.jsx
import { useContext } from 'react';
import ThemeContext from './ThemeContext';

function ThemeDisplay() {
    const theme = useContext(ThemeContext);

    return <h2>Current Theme: {theme}</h2>;
}

export default ThemeDisplay;

Expected Output

Current Theme: dark

3. Understanding Prop Drilling

Prop drilling happens when data must be passed through several intermediate components before reaching the component that actually needs it.

App.jsx
function App() {
    const studentName = 'Samadhan';

    return <Parent studentName={studentName} />;
}

function Parent({ studentName }) {
    return <Child studentName={studentName} />;
}

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

export default App;
App
↓ Props
Parent
↓ Props
Child

Parent forwards studentName without using it for its own purpose. For a small component tree, props are simple and perfectly reasonable. If many intermediate levels need to forward the same data, Context may reduce that extra work.

4. Passing Data Through Props

Consider a student portal where the App component passes a student's name through a Parent component to a Profile component.

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

function Parent({ studentName }) {
    return (
        <Profile studentName={studentName} />
    );
}

function Profile({ studentName }) {
    return (
        <h2>Welcome, {studentName}!</h2>
    );
}

export default App;

Expected Output

Welcome, Samiksha!

Every intermediate component must pass the value along until it reaches the Profile component.

5. Sharing Data Through Context

Now we can make the student name available through Context, allowing Profile to read it directly.

StudentContext.jsx
import { createContext } from 'react';

const StudentContext = createContext('Guest Student');

export default StudentContext;
App.jsx
import StudentContext from './StudentContext';
import Parent from './Parent';

function App() {
    return (
        <StudentContext.Provider value="Samiksha">
            <Parent />
        </StudentContext.Provider>
    );
}

export default App;
Parent.jsx
import Profile from './Profile';

function Parent() {
    return <Profile />;
}

export default Parent;
Profile.jsx
import { useContext } from 'react';
import StudentContext from './StudentContext';

function Profile() {
    const studentName = useContext(StudentContext);

    return <h2>Welcome, {studentName}!</h2>;
}

export default Profile;

Expected Output

Welcome, Samiksha!

Parent no longer needs to receive or forward studentName. Profile reads the value from StudentContext.

6. Context API vs Props: Comparison

Feature Props Context API
Purpose Pass data from parent to child. Share values with descendant components.
Data flow Explicitly passed through component props. Read through a matching Provider and useContext.
Intermediate components May need to forward props. Can skip forwarding values they do not use.
Best suited for Specific parent-to-child inputs. Values shared across several descendants.
Setup Pass props directly. Create Context and provide its value.
Updates Parent can pass updated props. Provider can supply an updated value, often using state.
Props and Context are not competitors. They solve related but different data-sharing needs and can be used together in the same application.

7. When Should You Use Props?

  • When passing a value to a direct child component.
  • When a component needs a specific title, label, or item.
  • When a parent needs to pass an event handler to a child.
  • When explicit data flow makes the component easier to understand.

Example

Course.jsx
function Course({ title }) {
    return <h2>Course: {title}</h2>;
}

export default Course;

A Course component receiving its title as a prop is a straightforward use of props.

8. When Should You Use Context API?

  • When many descendant components need the same theme.
  • When several components need the current user's information.
  • When multiple components need a shared language preference.
  • When forwarding the same value through many intermediate components becomes difficult to maintain.
Do not create Context for every piece of data. For values needed by only one or two nearby components, props may be easier to follow.

9. Can Props and Context Be Used Together?

Yes. Context can provide shared application information, while props can pass component-specific values.

CourseCard.jsx
import { useContext } from 'react';
import ThemeContext from './ThemeContext';

function CourseCard({ title }) {
    const theme = useContext(ThemeContext);

    return (
        <div>
            <h2>{title}</h2>
            <p>Current Theme: {theme}</p>
        </div>
    );
}

export default CourseCard;

In this example, title comes from props and theme comes from Context.

10. Common Mistakes

Mistake 1: Using Context for Every Value

Context is useful for shared information, but ordinary props are often simpler for direct parent-to-child communication.

Mistake 2: Forgetting the Provider

A component without a matching Provider above it receives the Context default value.

Mistake 3: Mutating Props

Props should be treated as read-only inputs. The parent should provide updated values rather than the child modifying its props.

Mistake 4: Assuming Context Replaces Props Completely

Context is not intended to eliminate props. Props remain useful for explicit component inputs and reusable components.

11. Practice Tasks

Complete these tasks to strengthen your understanding.

  1. Create a Student component that receives name and course through props.
  2. Pass data through three components and identify prop drilling.
  3. Create a StudentContext and display the student name without forwarding it through props.
  4. Create a ThemeContext and read its value inside a deeply nested component.
  5. Build a CourseCard component that receives its title through props and reads the theme from Context.
  6. Explain when props are more suitable than Context.
  7. Write five differences between Props and Context API.

Summary

Props pass explicit data and functions from a parent to its children, while Context makes shared values available to descendant components through a Provider. Props are suitable for direct component inputs, whereas Context can reduce prop drilling when many components need the same information. Both approaches can be used together to create clear, maintainable React applications.