1. Introduction

Chapter 1: Introduction to ReactJS

Discover the foundational philosophy behind ReactJS—how a simple paradigm shift from imperative DOM mutation to declarative, component-driven UI changed the modern software development landscape forever.

1. The Genesis of React: Why Was It Created?

Around 2010, the engineering team at Facebook faced an escalating complexity crisis with their web interface. As features like Facebook Chat, Real-Time Notifications, and the News Feed grew increasingly interconnected, maintaining state consistency across disparate parts of the page became nearly impossible.

A notorious manifestation of this bug was the "Zombie Notification" problem: a user would open a chat message, clearing the notification in the chat bar, yet the top notification globe would still show unread messages because the two independent DOM widgets failed to synchronize their state.

Jordan Walke, a software engineer at Facebook, proposed an unconventional solution heavily inspired by functional programming concepts from XHP (a PHP extension that allowed writing XML-like syntax directly in PHP) and functional languages like Standard ML. His prototype, initially dubbed FaxJS in 2011, evolved into React and was deployed to Facebook's News Feed in 2011, then Instagram in 2012, before being released as open-source software at JSConf US in May 2013.

📌 Key Historical Milestones
  • 2011: Jordan Walke authors FaxJS; deployed onto Facebook News Feed.
  • May 2013: React open-sourced at JSConf US (initially met with skepticism due to JSX combining HTML and JS).
  • 2015: React Native released, enabling native iOS and Android development with React paradigms.
  • 2018 (React 16.8): React Hooks introduced, replacing complex Class components with functional primitives.
  • 2022 (React 18): Concurrent Rendering, Automatic Batching, and Transitions released.
  • 2024-2025 (React 19): React Server Components (RSC), Actions, and compiler optimizations integrated.

2. Imperative vs. Declarative: The Core Mental Model

To truly understand React, one must grasp the fundamental distinction between imperative programming and declarative programming in UI engineering.

CriteriaImperative Programming (Vanilla JS / jQuery)Declarative Programming (React)
PhilosophyFocuses on HOW to update the DOM step-by-step.Focuses on WHAT the UI should look like for a given state.
DOM ManipulationManual queries (querySelector) and mutations (appendChild, innerHTML).React manages all DOM mutations automatically via the Virtual DOM.
State SyncingFragile: developers must remember to update every relevant DOM node whenever data changes.Reliable: UI automatically updates whenever state updates (UI = f(state)).
Bug Surface AreaHigh risk of out-of-sync UI states, memory leaks from dangling listeners.Predictable, isolated components with unidirectional data flow.

Code Comparison: Updating a Button Counter

Consider the classic counter button. Notice how much boilerplate and manual synchronization is needed in Vanilla JS compared to React:

❌ Imperative (Vanilla JavaScript)

// 1. Manually find the DOM nodes
const btn = document.getElementById('countBtn');
const text = document.getElementById('countDisplay');

let count = 0;

// 2. Attach manual listener
btn.addEventListener('click', () => {
  count++;
  // 3. Manually mutate the DOM node
  text.innerText = `Count is ${count}`;
});

If 5 other widgets on the page also need this count, you have to manually find and update all 5 nodes in every event listener.

✅ Declarative (React)

import { useState } from 'react';

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

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

You declare state with useState. When setCount is invoked, React re-renders the component and syncs the DOM seamlessly.

3. The Three Pillars of React Architecture

React's engineering power rests upon three central architectural concepts:

1. Component-Based Architecture

Instead of separating code into arbitrary technology layers (HTML files for markup, CSS files for styles, JS files for logic), React organizes your application into self-contained, reusable building blocks called components. Each component encapsulates its own markup, styling, and behavior.

2. The Virtual DOM & Reconciliation

Direct browser DOM manipulation is computationally expensive because it triggers browser layout reflows and repaints. React maintains an in-memory lightweight representation of the DOM tree (Virtual DOM). When state changes, React runs a heuristic diffing algorithm (Reconciliation) and performs batch updates to the real DOM.

3. Unidirectional Data Flow

Data flows strictly in one direction: from parent components down to child components via props. This prevents confusing cyclic dependencies where child components unexpectedly modify parent state without explicit handlers, making complex applications easy to reason about and debug.

4. Anatomy of a Modern React Application

Let's examine a standard modern React application entry point created with React 18+ and understand what every line executes:

// src/main.jsx (Entry Point)
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

// 1. Locate root DOM container
const rootElement = document.getElementById('root');

// 2. Create the React 18 Concurrent Root
const root = ReactDOM.createRoot(rootElement);

// 3. Render the Component Hierarchy
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

Step-by-Step Execution Breakdown:

  • document.getElementById('root'): Finds the single physical <div id="root"></div>in the host index.html file where the entire React application will be mounted.
  • ReactDOM.createRoot(): Replaces the legacy React 17 ReactDOM.render() API. It initializes React 18's concurrent rendering engine, enabling features like interruptible rendering, Suspense, and automatic state batching.
  • <React.StrictMode>: A development-only diagnostic wrapper that activates additional checks and warnings. In development mode, it intentionally re-invokes functional component renders and effects twice to help you identify side-effect bugs and deprecated lifecycle patterns before they reach production.
🔍 Under the Hood: What is JSX Actually?

Browsers do not understand JSX (<h1>Hello</h1>) natively. JSX is purely syntactic sugar. During the build process, a compiler like Babel or SWC transforms your JSX tags into standard JavaScript calls:

// What you write:
const element = <h1 className="title">Hello World</h1>;

// What the compiler outputs:
const element = React.createElement('h1', { className: 'title' }, 'Hello World');

React.createElement() creates a plain JavaScript object representing the DOM node, known as a React Element!

Frequently Asked Questions (FAQ)

Who created React and when was it released?

React was created by Jordan Walke, a software engineer at Meta (Facebook). It was first deployed on Facebook's News Feed in 2011, introduced to Instagram in 2012, and officially open-sourced at JSConf US in May 2013.

What is the primary difference between Declarative and Imperative UI?

Imperative programming requires you to specify every step-by-step instruction to mutate the DOM (e.g., document.getElementById, createElement, appendChild). Declarative programming allows you to describe what the UI should look like for a given state, and React handles the DOM updates automatically.

What is the Virtual DOM and why does React use it?

The Virtual DOM is a lightweight JavaScript object representation of the real browser DOM. React uses it to compute diffs (differences) when state changes via its reconciliation algorithm, batching and applying only the minimal necessary updates to the actual browser DOM to prevent expensive layout reflows.

Can React be used for full-stack development?

Yes. While React began as a client-side library, modern React (versions 18 and 19) introduces React Server Components (RSC) and Server Actions, which enable full-stack development within frameworks like Next.js and Remix.

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools