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

JSX Attributes

Learn how to add attributes to JSX elements, use JavaScript expressions in attributes, apply CSS classes, and handle common JSX attribute rules.

1. What Are JSX Attributes?

JSX attributes provide additional information to elements. They are similar to HTML attributes, but some attribute names are different in JSX because JSX follows JavaScript naming conventions.

Example: <img src="/images/react.png" alt="React Logo" />

Here, src specifies the image location and alt provides alternative text.

2. JSX Attributes — Visual Diagram

A JSX element can contain a tag name, attributes, attribute values, and content.

<button className = "primary-btn" disabled = {true} > Enroll Now </button>
Tag button

Defines the element.

Attribute className

Defines an element property.

Attribute value "primary-btn"

Specifies the CSS class.

Expression {true}

Uses a JavaScript value.

JSXAttributes.jsx JSX
function App() {
    return (
        <button className="primary-btn" disabled={true}>
            Enroll Now
        </button>
    );
}

export default App;

3. String Attributes

Use quotation marks to provide a string value to a JSX attribute.

StringAttributes.jsx JSX
function App() {
    return (
        <div>
            <h2 title="React Tutorial">
                Learn React
            </h2>

            <a href="http://ciitstacklab.com/">
                Official React Website
            </a>
        </div>
    );
}

export default App;

Expected Browser Output

Browser Output

4. Using JavaScript Expressions in Attributes

Curly braces allow you to pass variables and JavaScript expressions as attribute values.

DynamicAttributes.jsx JSX
function App() {
    const courseName = "React JS";
    const imagePath = "/images/react-logo.png";
    const isDisabled = true;

    return (
        <div>
            <h2 title={courseName}>
                {courseName}
            </h2>

            <img
                src={imagePath}
                alt="React Logo"
                width={120}
            />

            <button disabled={isDisabled}>
                Enroll Now
            </button>
        </div>
    );
}

export default App;
Remember: Use title="React JS" for a literal string and title={courseName} for a JavaScript variable.

5. className Instead of class

In JSX, use className to assign a CSS class to an element. This follows the JavaScript DOM property naming convention.

HTML syntax <h2 class="heading">Hello</h2>
JSX syntax <h2 className="heading">Hello</h2>
ClassNameExample.jsx JSX
function App() {
    return (
        <div className="course-card">
            <h2 className="course-title">
                React Full Stack
            </h2>
            <p className="course-description">
                Learn React step by step.
            </p>
        </div>
    );
}

export default App;

6. JSX Attribute Naming Rules

Many JSX DOM event and property names use camelCase. Some familiar HTML attributes also have JSX-specific names.

HTML Attribute JSX Attribute Purpose
class className Assigns a CSS class.
for htmlFor Connects a label to a form control.
onclick onClick Handles a click event.
tabindex tabIndex Controls keyboard tab order.
readonly readOnly Makes a field read-only.
FormAttributes.jsx JSX
function App() {
    return (
        <div>
            <label htmlFor="studentName">
                Student Name
            </label>

            <input
                id="studentName"
                type="text"
                readOnly={true}
                value="Priya"
            />
        </div>
    );
}

export default App;

7. Boolean Attributes

Boolean attributes represent true or false states. For example, disabled disables a button when its value is true.

BooleanAttributes.jsx JSX
function App() {
    const canEnroll = false;

    return (
        <div>
            <button disabled={!canEnroll}>
                Enroll Now
            </button>

            <button disabled={false}>
                View Courses
            </button>
        </div>
    );
}

export default App;
Illustrative Browser Output

8. Inline Styles in JSX

JSX uses a JavaScript object for inline styles. CSS property names are generally written in camelCase, and string values are used for values such as colors.

InlineStyleExample.jsx JSX
function App() {
    const headingStyle = {
        color: "blue",
        backgroundColor: "lightyellow",
        padding: "12px",
        borderRadius: "8px"
    };

    return (
        <h2 style={headingStyle}>
            Welcome to CIIT Training Institute
        </h2>
    );
}

export default App;

Expected Browser Output

Browser Output

Welcome to CIIT Training Institute

Important: The JSX style attribute expects an object, so use style={headingStyle}, not a CSS string.

9. Common Mistakes

Using class instead of className

Avoid in JSX:

<div class="box">Hello</div>

Use:

<div className="box">Hello</div>

Passing a variable without curly braces

Incorrect for a variable:

<img src="imagePath" alt="Course" />

Correct:

<img src={imagePath} alt="Course" />

Using a CSS string in the style attribute

Incorrect:

style="color: blue"

Correct:

style={{ color: "blue" }}

Using lowercase event names

Incorrect:

onclick={handleClick}

Correct:

onClick={handleClick}

10. Practice Questions

  1. Create a heading with a title attribute.
  2. Display a course image using a variable in the src attribute.
  3. Create a button with a dynamic disabled attribute.
  4. Build a student form using htmlFor and className.
  5. Apply inline styles using a JavaScript object.

11. Summary

  • JSX attributes configure elements.
  • String values can be provided inside quotation marks.
  • Curly braces allow JavaScript expressions as attribute values.
  • Use className instead of class.
  • Use camelCase for many JSX event and DOM property names.
  • Inline styles use JavaScript objects.
  • Boolean attributes can control element states.