What is React — Component Model, Virtual DOM and Declarative UI

React is a JavaScript library for building user interfaces, developed by Meta and released in 2013. Its core insight is simple but transformative: instead of imperatively manipulating the DOM when data changes (“find this element, change its text, add this class”), you declare what the UI should look like for a given state (“when loading is true, show a spinner; otherwise show the posts”). React figures out the minimal DOM updates needed. This declarative model — combined with the component abstraction — makes complex UIs manageable, predictable, and reusable.

React’s Core Concepts

// ── Imperative (vanilla JS) — describing HOW to update ────────────────────────
function updatePostCount(count) {
    const el = document.getElementById("post-count");
    el.textContent = count + " posts";
    if (count === 0) {
        el.style.color = "gray";
    } else {
        el.style.color = "black";
    }
}

// ── Declarative (React) — describing WHAT to show ─────────────────────────────
function PostCount({ count }) {
    return (
        <span style={{ color: count === 0 ? "gray" : "black" }}>
            {count} posts
        </span>
    );
}
// React figures out the DOM updates automatically when count changes
// You only describe the desired output for each possible value of count
Note: React’s virtual DOM is a lightweight JavaScript representation of the real DOM. When state changes, React re-renders the component tree in memory (fast), compares the new virtual DOM to the previous one (diffing), and applies only the minimal set of real DOM changes needed (reconciliation). This is why React can update complex UIs efficiently — it never does more DOM work than necessary. For the blog application, this means smooth updates when new posts load, comments appear, or like counts change.
Tip: React’s component model maps naturally to the way designers think about UI — a page is composed of sections, sections are composed of cards, cards are composed of buttons and text. Every piece of UI in the blog application is a component: PostCard, CommentList, LikeButton, AuthorAvatar. Components can be nested, reused across pages, tested in isolation, and updated independently. This composability is React’s superpower for large applications.
Warning: React is a library, not a full framework — it handles only the view layer. Unlike Next.js (which adds routing, server rendering, and data fetching on top of React), plain React needs additional libraries for routing (React Router), data fetching (TanStack Query or SWR), and state management (Zustand, Redux, or React Context). For the blog application in this series, you will add these libraries incrementally as each need arises.

React vs the Alternatives

Feature React Vue Angular Vanilla JS
Type Library (view only) Framework (progressive) Full framework No framework
Learning curve Moderate Low–Medium High Low to start
Component model Function + hooks Single File Components Class-based + DI Custom
Ecosystem Very large Large Large (enterprise) Manual
Used by Meta, Airbnb, Atlassian Alibaba, Xiaomi, GitLab Google, Microsoft Everywhere
Best for SPAs, complex UIs Progressive enhancement Enterprise apps Simple pages

How React Renders

// React rendering pipeline:
// 1. You write components (JSX)
// 2. Babel/SWC compiles JSX to React.createElement() calls
// 3. React builds a virtual DOM tree (plain JS objects)
// 4. ReactDOM renders the virtual DOM to the real DOM (initial render)
// 5. On state changes: React re-renders, diffs, and patches the real DOM

// JSX:
const element = <h1 className="title">Hello, {name}!</h1>;

// Compiled to:
const element = React.createElement(
    "h1",
    { className: "title" },
    "Hello, ", name, "!"
);

// Virtual DOM node (just a JS object):
// { type: "h1", props: { className: "title", children: ["Hello, ", name, "!"] } }

// React compares this object to the previous render and updates only
// the text node in the real DOM if 'name' changed — not the whole h1

Common Mistakes

Mistake 1 — Treating React as a full framework

❌ Wrong — expecting built-in routing, HTTP client, or server-side rendering:

React is a view library. You need React Router for navigation, fetch/axios for HTTP, and Next.js for SSR. Plan your library stack before starting a new project.

✅ Correct — understand what React does (UI components) and what it does not do, then choose the right additional libraries.

Mistake 2 — Directly mutating the DOM alongside React

❌ Wrong — mixing jQuery or document.getElementById with React components:

// React manages the DOM. Manually mutating it bypasses React's virtual DOM
document.getElementById("my-react-div").innerHTML = "changed";
// React's next re-render overwrites this change → unpredictable!

✅ Correct — always use React’s state and refs to interact with the DOM inside React components.

Quick Reference

Concept Description
Component A function that returns JSX — the UI building block
Props Data passed to a component from its parent
State Data managed inside a component that triggers re-renders
Virtual DOM JS representation of UI; React diffs it to update the real DOM
Declarative Describe the desired output; React handles DOM updates
JSX HTML-like syntax in JS; compiled to React.createElement() calls

🧠 Test Yourself

You have a React component that shows a post’s like count. The count updates every 5 seconds from an API. What is React’s role in handling this update?