⚛️ What is React?

Introduction to React - The JavaScript Library for User Interfaces

Welcome to React!

React is a powerful JavaScript library for building user interfaces, created and maintained by Facebook (Meta). It has revolutionized web development since its release in 2013 and is now used by millions of developers worldwide.

🎯 Key Facts

  • Created by: Facebook (Jordan Walke) in 2013
  • Type: JavaScript library (not a framework)
  • Focus: Building user interfaces
  • Used by: Facebook, Instagram, Netflix, Airbnb, Uber
  • License: MIT (open source)

🤔 Why React?

1. Component-Based Architecture

React lets you build encapsulated components that manage their own state, then compose them to create complex UIs.

// A simple React component
function Welcome(props) {
  return <h1>Hello, {props.name}!</h1>;
}

// Use it multiple times
<Welcome name="Alice" />
<Welcome name="Bob" />
<Welcome name="Charlie" />

2. Virtual DOM

React creates a virtual representation of the UI in memory. When state changes, React efficiently updates only what needs to change in the actual DOM.

How Virtual DOM Works:

  1. Change in state triggers virtual DOM update
  2. React compares new virtual DOM with previous version
  3. Calculates the minimum changes needed (diffing)
  4. Updates only changed parts in real DOM

Result: Much faster than traditional DOM manipulation!

3. Learn Once, Write Anywhere

🎨 React Philosophy

Declarative

Tell React what you want, not how to do it. React figures out the details.

// ❌ Imperative (vanilla JS)
const button = document.getElementById('myButton');
button.addEventListener('click', () => {
  const counter = document.getElementById('counter');
  const current = parseInt(counter.textContent);
  counter.textContent = current + 1;
});

// ✅ Declarative (React)
function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}

Component-Based

Build small, reusable pieces. Combine them like LEGO blocks.

// Small components
function Header() { return <header>My App</header>; }
function Sidebar() { return <aside>Menu</aside>; }
function Content() { return <main>Content</main>; }

// Compose them
function App() {
  return (
    <div>
      <Header />
      <Sidebar />
      <Content />
    </div>
  );
}

Unidirectional Data Flow

Data flows in one direction: parent → child. This makes apps predictable and easier to debug.

📊 React vs Other Frameworks

Feature React Vue Angular
Type Library Framework Framework
Learning Curve Moderate Easy Steep
Syntax JSX Templates TypeScript
Popularity Very High High High
Mobile React Native Vue Native Ionic
Used by Facebook, Netflix Alibaba, GitLab Google, Microsoft

🌟 Core Concepts

1. JSX - JavaScript XML

A syntax extension that looks like HTML but is actually JavaScript.

const element = <h1>Hello, world!</h1>;

2. Components

Reusable pieces of UI. Can be functions or classes (modern React uses functions).

function Greeting() {
  return <h1>Welcome!</h1>;
}

3. Props

Properties passed from parent to child components (like function arguments).

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

<Welcome name="Alice" />

4. State

Data that changes over time. When state changes, component re-renders.

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <button onClick={() => setCount(count + 1)}>
      Clicked {count} times
    </button>
  );
}

5. Hooks

Special functions that let you "hook into" React features in function components.

🚀 Why Learn React in 2025?

🎯 What You'll Build with React

Common React Applications:

  • Social Media: Facebook, Instagram
  • E-commerce: Shopify stores, product catalogs
  • Streaming: Netflix, Hulu interfaces
  • Dashboards: Admin panels, analytics
  • Productivity: Trello, Asana, Notion
  • Documentation: Docusaurus, Gatsby sites

📚 Prerequisites

Before learning React, you should know:

Don't worry if you're not an expert! We'll review important concepts as needed.

🎓 React Ecosystem

Essential Tools

Popular Libraries

🎯 Key Takeaways

🚀 Ready to Start?

Now that you understand what React is and why it's popular, let's set it up and start building!

Next Steps:

  1. Set up your development environment
  2. Create your first React app
  3. Learn JSX syntax
  4. Build your first components