Lesson 1 of 60 – Introduction to React
2%

Introduction to React

React is a JavaScript library used for building interactive and reusable user interfaces. It is commonly used to create modern web applications where the page can update dynamically without requiring a complete page reload.

Note: React helps developers build user interfaces using reusable components. To work with React effectively, you should have a basic understanding of HTML, CSS, and JavaScript.

1. What is React?

React is a JavaScript library for creating user interfaces. It allows developers to divide an application interface into smaller and reusable components.

React
  ↓
User Interface
  ↓
Components
  ↓
Web Application

React is especially useful for building interactive web applications.

2. React is a JavaScript Library

React is built around JavaScript. You use JavaScript concepts such as variables, functions, objects, arrays, conditions, and events while developing React applications.

JavaScript
     ↓
   React
     ↓
Interactive UI

3. Why Learn React?

React is useful for developers who want to build modern and interactive web applications.

  • Build reusable interfaces
  • Create interactive applications
  • Organize applications into components
  • Manage changing data
  • Build single-page applications
  • Work with APIs

4. React Components

A React application is commonly divided into components. A component can represent a part of the user interface.

Application
    |
    +-- Header
    |
    +-- Navigation
    |
    +-- Content
    |
    +-- Footer

Each part can be developed as a reusable component.

5. Reusable Components

One of the important ideas in React is component reusability. A component can be used in multiple places in an application.

Button Component
      ↓
Login Page
      ↓
Register Page
      ↓
Contact Page

6. React and User Interfaces

React focuses on building user interfaces. The interface can respond to user actions such as clicking buttons, entering information, and selecting options.

User Action
     ↓
React Code
     ↓
UI Update

7. React and JavaScript

React does not replace JavaScript. Instead, React provides tools and patterns that make it easier to create complex user interfaces.

JavaScript + React
        ↓
Interactive User Interface

8. What is JSX?

JSX is a syntax commonly used in React applications. It allows developers to write HTML-like markup inside JavaScript code.

function Welcome() {
    return <h1>Hello React</h1>;
}

JSX makes the structure of a React user interface easier to read.

9. Simple React Component

function Welcome() {
    return <h1>Welcome to React</h1>;
}

Here, Welcome is a React component that returns a user interface element.

10. Rendering a Component

A component can be used as part of the application's user interface. For example:

<Welcome />

This syntax represents the use of the Welcome component.

11. React Applications

A React application can contain many components working together.

React Application
        |
        +-- Header
        +-- Sidebar
        +-- ProductList
        +-- Product
        +-- Footer

This component-based structure helps organize larger applications.

12. Interactive Interfaces

React can update the user interface when application data changes. For example, a button click can change information displayed on the screen.

Click Button
     ↓
Data Changes
     ↓
Interface Updates

13. React and State

React applications often use state to represent data that can change during the lifetime of a component.

State
  ↓
Data Changes
  ↓
Component Updates
  ↓
UI Changes

The useState Hook is commonly used to manage state in functional components.

14. React Events

React supports handling user events such as clicks, keyboard input, form submission, and mouse actions.

<button onClick={handleClick}>
    Click Me
</button>

Event handling allows applications to respond to user interaction.

15. React and Forms

React can be used to create interactive forms for collecting user input.

<input
    type="text"
    placeholder="Enter your name"
/>

React can also manage and validate form values.

16. Conditional Rendering

React can display different content based on a condition.

{isLoggedIn ? (
    <Dashboard />
) : (
    <Login />
)}

This is useful for displaying different parts of an application depending on the current state.

17. Rendering Lists

React can display multiple elements from an array of data. The JavaScript map() method is commonly used for this.

const students = ["Amit", "Ravi", "Neha"];

students.map(student => (
    <li>{student}</li>
));

18. Props in React

Props are values passed from one component to another component. They can be used to make components reusable.

<Student name="Amit" />

The Student component can receive the name value as a prop.

19. React Hooks

Hooks are functions that allow functional components to use React features such as state and other capabilities.

Common Hooks include:

  • useState
  • useEffect
  • useRef
  • useContext
  • useReducer

20. useState Hook

The useState Hook can be used to create and update state inside a functional component.

import { useState } from "react";

function Counter() {

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

    return (
        <button onClick={() => setCount(count + 1)}>
            {count}
        </button>
    );
}

21. useEffect Hook

The useEffect Hook is commonly used for side effects in React components.

Examples of side effects include working with APIs, subscriptions, and other operations that happen as part of the component's behavior.

import { useEffect } from "react";

22. React Router

React Router is commonly used to manage navigation and routes in React applications.

/home
/about
/contact
/products

It allows different views or components to be associated with different URLs.

23. React and APIs

React applications can communicate with APIs to retrieve or send data.

React Application
       ↓
      API
       ↓
   Database
       ↓
      API
       ↓
React Application

JavaScript functions such as fetch() can be used to make HTTP requests.

24. React and JSON

APIs commonly exchange data in JSON format. React applications can read JSON data and display it in the user interface.

{
    "name": "Amit",
    "age": 22,
    "course": "React"
}

25. React Developer Tools

React Developer Tools can help developers inspect React components and understand component-related information while developing an application.

Developer tools are useful for debugging and understanding the structure of a React application.

26. React Project Structure

A React project commonly contains source files, components, public assets, configuration files, and dependency information.

my-react-app/
│
├── public/
├── src/
│   ├── App.jsx
│   ├── main.jsx
│   └── components/
│
├── package.json
└── node_modules/

27. React and npm

React projects commonly use the Node.js ecosystem and npm or another JavaScript package manager to install and manage dependencies.

npm install
npm run dev

The exact commands can depend on how the React project was created.

28. React Single-Page Applications

React is commonly used to build single-page applications, where the browser can update the displayed interface dynamically as the user interacts with the application.

Browser
   ↓
React Application
   ↓
Components
   ↓
Dynamic UI

29. What You Will Learn in This Tutorial

In this React tutorial, you will gradually learn the important concepts needed to build React applications.

  • React fundamentals
  • JSX
  • Components
  • Props
  • Events
  • Forms
  • Hooks
  • State management
  • React Router
  • API integration
  • Authentication concepts
  • Project development

30. Simple React Learning Path

JavaScript
     ↓
React Basics
     ↓
JSX
     ↓
Components
     ↓
Props
     ↓
Events
     ↓
State
     ↓
Hooks
     ↓
Forms
     ↓
Routing
     ↓
APIs
     ↓
Projects

Following these concepts step by step will help you build a strong foundation for developing React applications.

📌 Key Points

  • React is a JavaScript library for building user interfaces.
  • React applications are commonly built using reusable components.
  • JSX allows HTML-like markup to be written inside JavaScript.
  • Props are used to pass data between components.
  • State represents data that can change in a component.
  • Hooks provide React features to functional components.
  • React can handle events and forms.
  • React can render lists and conditionally display content.
  • React applications can communicate with APIs.
  • React Router can be used for application navigation.
  • React is commonly used to build interactive web applications.
  • Basic JavaScript knowledge is important before learning React.

🧠 Quick Quiz

Question: What is React?