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 Types

Learn how to document and validate the types of props passed to React components using PropTypes.

01 What Are PropTypes?

PropTypes is a runtime type-checking utility for React props. It helps developers identify when a component receives a value that does not match the expected type during development.

PropTypes Validation Flow
Parent Component Passes data to a child
↓
Child Component Receives props
↓
Correct Type Validation passes
Incorrect Type Development warning
PropTypes helps catch mistakes during development. It is not a replacement for validating untrusted data in a backend or API.
Expected Browser Output

PropTypes checks whether supplied props match the declared types.

02 Installing PropTypes

In a React project that uses PropTypes, install the prop-types package using the terminal.

Terminal
npm install prop-types

After installation, import PropTypes into the component file where you want to declare the expected types.

Student.jsx
import PropTypes from "prop-types";
Expected Terminal Output

The prop-types package is added to the project dependencies.

Exact terminal messages may differ depending on the package manager and project.

03 Validating a String Prop

Use PropTypes.string when a prop is expected to contain a string value.

Student.jsx
import PropTypes from "prop-types";

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

Student.propTypes = {
    name: PropTypes.string
};

export default Student;

The name prop is expected to be a string. The declaration does not automatically make the prop required.

Expected Browser Output

Student Name: Samadhan

04 Validating Multiple Prop Types

PropTypes provides validators for common JavaScript data types, including strings, numbers and booleans.

Student.jsx
import PropTypes from "prop-types";

function Student({ name, age, isEnrolled }) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Age: {age}</p>
            <p>Enrolled: {isEnrolled ? "Yes" : "No"}</p>
        </div>
    );
}

Student.propTypes = {
    name: PropTypes.string,
    age: PropTypes.number,
    isEnrolled: PropTypes.bool
};

export default Student;
Prop Type Mapping
name PropTypes.string
age PropTypes.number
isEnrolled PropTypes.bool
Expected Browser Output

Samiksha

Age: 22

Enrolled: Yes

05 Making Props Required

Add .isRequired when a prop must be supplied. If it is missing during development, PropTypes reports a warning.

Student.jsx
import PropTypes from "prop-types";

function Student({ name, age }) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Age: {age}</p>
        </div>
    );
}

Student.propTypes = {
    name: PropTypes.string.isRequired,
    age: PropTypes.number.isRequired
};

export default Student;
A required PropTypes declaration is a development-time check, not a runtime mechanism that prevents a component from rendering.
Expected Browser Output

Pradnya

Age: 23

Both required props are supplied in this example.

06 Validating an Array

Use PropTypes.array to check that a prop is an array. Use PropTypes.arrayOf() to check the type of each item.

Student.jsx
import PropTypes from "prop-types";

function Student({ skills }) {
    return (
        <ul>
            {skills.map(skill => (
                <li key={skill}>{skill}</li>
            ))}
        </ul>
    );
}

Student.propTypes = {
    skills: PropTypes.arrayOf(PropTypes.string).isRequired
};

export default Student;
Expected Browser Output
  • HTML
  • CSS
  • JavaScript

07 Validating an Object

Use PropTypes.shape() to describe the expected properties of an object prop.

Student.jsx
import PropTypes from "prop-types";

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

Student.propTypes = {
    details: PropTypes.shape({
        name: PropTypes.string.isRequired,
        course: PropTypes.string.isRequired
    }).isRequired
};

export default Student;
Expected Browser Output

Samadhan

Course: React JS

08 Validating Specific Values

Use PropTypes.oneOf() when a prop should match one of a specific set of values.

Course.jsx
import PropTypes from "prop-types";

function Course({ level }) {
    return <p>Course Level: {level}</p>;
}

Course.propTypes = {
    level: PropTypes.oneOf([
        "Beginner",
        "Intermediate",
        "Advanced"
    ]).isRequired
};

export default Course;
Allowed Values
Beginner
Intermediate
Advanced
↓
Course Level One of the allowed values
Expected Browser Output

Course Level: Intermediate

09 Default Props with PropTypes

PropTypes describes and checks expected types. Default values provide fallback data. In a functional component, you can specify defaults during parameter destructuring.

Student.jsx
import PropTypes from "prop-types";

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

Student.propTypes = {
    name: PropTypes.string
};

export default Student;
PropTypes and default values serve different purposes: PropTypes checks the expected type, while the default supplies a fallback when the prop is undefined.
Expected Browser Output

Student Name: Guest

10 Complete PropTypes Example

This example validates a student's name, age and skills array in one reusable component.

Student.jsx
import PropTypes from "prop-types";

function Student({ name, age, skills }) {
    return (
        <div>
            <h2>{name}</h2>
            <p>Age: {age}</p>
            <h3>Skills
        

Example parent component:

App.jsx
import Student from "./Student";

function App() {
    return (
        <Student
            name="Pradnya"
            age={23}
            skills={["React JS", "JavaScript", "CSS"]}
        />
    );
}

export default App;
Complete Validation Flow
App Passes name, age and skills
↓
Student Receives the props
↓
name string
age number
skills array of strings
Expected Browser Output

Pradnya

Age: 23

Skills

  • React JS
  • JavaScript
  • CSS

Summary

PropTypes helps document and validate the expected types of props passed to React components during development. Common validators include string, number, bool, arrayOf, shape and oneOf. Use isRequired for props that should be supplied, and use default values separately when fallback data is needed. PropTypes improves code clarity and helps identify incorrect component inputs while building reusable interfaces at CIIT Training Institute.