Skip to main content

βš›οΈ React Library Overview

React reshaped how the web is built by turning interfaces into small, reusable, declarative components. Before you install anything, this lesson gives you the mental model: what React actually is (a library, not a framework), how the Virtual DOM makes it fast, and where it sits among the tools you'll use every day.

🎯 Learning Objectives

By the end of this lesson, you will be able to:

  • Define React as a declarative, component-based library and explain what that means in practice
  • Describe how the Virtual DOM and reconciliation minimize expensive DOM updates
  • Map the core React ecosystem β€” routing, state management, data fetching, and meta-frameworks
  • Compare React with Angular and Vue and decide when React is the right fit
  • Break a real interface into a component hierarchy

Estimated Time: 30–40 minutes  β€’  Difficulty: Beginner

Hands-on: Deconstruct a website you use daily into a labeled React component tree.

In This Lesson

What Is React?

React is a JavaScript library for building user interfaces out of small, composable pieces called components. It was created at Facebook (now Meta) by Jordan Walke and first open-sourced in 2013. Today it is maintained by Meta together with a large community, and it powers the interfaces of Facebook, Instagram, Netflix, and countless others.

The word library is deliberate. Unlike a full framework such as Angular β€” which ships routing, forms, HTTP, and dependency injection in one box β€” React does one job: it renders your UI and keeps it in sync with your data. You add the other pieces (routing, data fetching, global state) yourself, choosing the tools that fit the project. That focus is React's greatest strength and the source of its famous "decision fatigue."

πŸ’‘ The core idea in one sentence: You describe what the UI should look like for any given state, and React figures out how to update the screen to match. You never hand-write "find this element and change its text" β€” you change the data and let React reconcile the difference.

πŸ“– Key Terms

Declarative: you write the target state ("show these three items"), not the step-by-step DOM instructions to get there.

Component: a self-contained, reusable function that returns a description of some UI.

Library vs. framework: a library is a tool you call; a framework is a structure that calls you. React is the former.

Five Defining Characteristics

Almost everything distinctive about React comes back to these five ideas:

  • Component-based: the entire UI is a tree of components, each owning its own markup, logic, and (optionally) styles.
  • Declarative: you describe the end result; React handles the DOM operations to reach it.
  • Virtual DOM: React keeps a lightweight in-memory copy of the UI, diffs it on each update, and touches the real DOM as little as possible.
  • Unidirectional data flow: data flows down from parent to child through props, which makes apps easier to reason about.
  • JSX: a syntax extension that lets you write markup-like code directly inside JavaScript (covered in depth two lessons from now).

βœ… Why this combination works

Small components are easy to test and reuse. Declarative code is easier to read than a pile of manual DOM edits. And one-way data flow means when something looks wrong on screen, there is exactly one place the data could have come from β€” the parent that passed it down.

The Virtual DOM, Made Concrete

Directly changing the browser's DOM is slow. Every change can trigger layout recalculation and repainting, and doing many small edits in a complex UI adds up fast. React's answer is the Virtual DOM: a plain JavaScript object tree that mirrors the real DOM but is cheap to create and compare.

When your data changes, React does not rush to the browser. Instead it:

  1. Builds a new Virtual DOM tree that reflects the updated state.
  2. Diffs it against the previous Virtual DOM tree (this step is called reconciliation).
  3. Calculates the minimum set of real DOM operations needed to close the gap.
  4. Applies only those specific changes to the actual DOM in one efficient batch.
How the Virtual DOM update cycle works A previous Virtual DOM tree and a new Virtual DOM tree are compared by a diff step, which produces a minimal patch applied to the real DOM. Previous Virtual DOM New Virtual DOM changed diff Real DOM one patch only update row 2 patch
Figure 1 β€” React compares the new tree to the old one and applies only the single row that actually changed, rather than rebuilding the whole list.
🏠 A renovation analogy: Editing the real DOM directly is like tearing down and rebuilding walls for every small change. The Virtual DOM is like marking up a blueprint first, comparing it to the current house, and then only sending the crew to move the one wall that actually moved.

⚠️ A common misconception

The Virtual DOM is not "faster than the DOM" by magic β€” creating and diffing trees costs time too. Its win is that it lets React batch and minimize real DOM writes, which are the genuinely expensive part. For most apps this is plenty fast; when it isn't, you optimize with memoization and keys.

The React Ecosystem

Because React itself only handles rendering, real applications pull in companion libraries. Here is the map of the pieces you'll meet most often:

graph TD React["React Core
(components & state)"] --> DOM["React DOM
(renders to the browser)"] React --> Native["React Native
(mobile apps)"] DOM --> Router["React Router
(navigation)"] DOM --> State["State: Redux Toolkit,
Zustand, Context"] DOM --> Data["Data: TanStack Query,
SWR, Apollo"] DOM --> UI["UI kits: MUI, Chakra,
Radix, shadcn/ui"] DOM --> Meta["Meta-frameworks:
Next.js, Remix"]
NeedPopular choicesWhat it does
RoutingReact RouterMaps URLs to components in a single-page app
Server stateTanStack Query, SWRFetching, caching, and refreshing remote data
Client stateZustand, Redux Toolkit, ContextSharing app-wide state between components
UI componentsMUI, Chakra, shadcn/uiPre-built accessible buttons, forms, dialogs
Full frameworkNext.js, RemixRouting, SSR, and data loading built in

πŸ’‘ You don't need all of this on day one

A first React app needs only React and React DOM (or Vite's template, which wires both up). Add routing when you have more than one page, and reach for a data or state library only when passing props around becomes painful. Start small.

Thinking in Components

The single most important habit in React is learning to see an interface as a tree of components. A component returns a description of some UI, and components nest inside one another to form the page.

graph TD App[App] --> Nav[NavBar] App --> Feed[Feed] Nav --> Logo[Logo] Nav --> Search[SearchBar] Feed --> Post1[Post] Feed --> Post2[Post] Post1 --> Header[PostHeader] Post1 --> Actions[PostActions]
🧱 The LEGO analogy: Components are like LEGO bricks. Each brick is reusable (use it in many places), composable (snap small ones into bigger structures), encapsulated (it manages its own look and behavior), and hierarchical (bricks contain bricks). You build a big app the same way you build a big model β€” one small, well-shaped piece at a time.

Here is how the top of an Instagram-style feed might decompose into modern function components. Notice how each component does one job and the data flows downward through props:

// App β€” the top-level container
function App() {
  return (
    <div className="instagram-app">
      <NavBar />
      <main>
        <Stories />
        <Feed />
      </main>
    </div>
  );
}

// Feed β€” turns an array of posts into <Post> elements
function Feed({ posts }) {
  return (
    <div className="instagram-feed">
      {posts.map((post) => (
        <Post key={post.id} post={post} />
      ))}
    </div>
  );
}

// Post β€” receives one post via props and renders its parts
function Post({ post }) {
  return (
    <article className="instagram-post">
      <PostHeader username={post.username} avatar={post.avatar} />
      <PostImage src={post.image} alt={post.caption} />
      <PostActions likes={post.likes} />
    </article>
  );
}

Each of these components could be developed, styled, and tested on its own β€” and reused elsewhere. That is the whole promise of component-based design in one screen of code.

React vs. Angular vs. Vue

React is one of three dominant choices for building browser UIs. They solve the same problem with different philosophies:

AspectReactAngularVue
TypeLibraryFull frameworkProgressive framework
Learning curveModerateSteepGentle
Data bindingOne-wayTwo-wayBoth supported
State managementExternal (Redux, Zustand…)Built-in servicesPinia
TemplatingJSX (in JavaScript)HTML + directivesHTML templates
LanguageJavaScript / TypeScriptTypeScript-firstJavaScript / TypeScript

Library vs. framework, again: Angular hands you an opinionated, batteries-included structure β€” great for large teams that want consistency, at the cost of a steeper ramp. React gives you a small, flexible core and lets you assemble the rest, which suits teams that value freedom. Vue sits in between, approachable for newcomers while scaling up when needed.

πŸ“– Who uses what

React: Meta, Netflix, Airbnb, Dropbox. Angular: Google, Microsoft Office, Forbes. Vue: Alibaba, GitLab, Adobe. All three are production-proven β€” the "best" one is the one your team can build and maintain well.

When to Choose React

React shines when…

  • You're building a rich single-page application β€” interactive UIs that update pieces of the screen without full reloads.
  • Your interface is complex and state-driven β€” dashboards, editors, feeds, anything with lots of moving UI.
  • You want to reuse skills across platforms β€” the same mental model powers React Native for mobile.
  • You need to adopt incrementally β€” React can be dropped into a single widget on an existing page.

Weigh the trade-offs when…

  • Decision fatigue: the freedom to pick your own router, state, and data libraries can overwhelm newcomers.
  • Fast-moving ecosystem: tools evolve quickly, so expect ongoing learning.
  • SEO and first paint: pure client-side rendering can hurt search indexing and initial load β€” solved by meta-frameworks like Next.js that render on the server.

πŸ’‘ The modern default

The React team now recommends starting most new projects with a framework such as Next.js. For pure learning, though, a plain Vite + React app keeps the moving parts minimal β€” which is exactly why the next lesson uses Vite.

Hands-on Exercise

πŸ‹οΈ Deconstruct a Real Interface into Components

Objective: Train your eye to see any UI as a React component tree.

Instructions:

  1. Open a website you use often (YouTube, a news site, an online shop).
  2. Take a screenshot of one screen.
  3. Draw boxes around distinct, repeatable UI chunks β€” a nav bar, a search box, a card, a list item.
  4. Give each box a PascalCase component name (e.g. VideoCard, SearchBar).
  5. Sketch the parent-child hierarchy: which boxes live inside which. Mark which components would repeat (rendered from an array with a key).
πŸ’‘ Hint

Anything that appears more than once with the same shape β€” a product tile, a comment, a row β€” is almost certainly one component rendered in a loop. The whole page is usually a single top-level App containing a handful of big regions.

βœ… Example answer (YouTube home)

App β†’ Header (contains Logo, SearchBar, UserMenu) + Sidebar (list of SidebarLink) + VideoGrid (list of VideoCard, each with a Thumbnail, ChannelAvatar, and VideoMeta). The VideoCard is the big reusable win β€” one component, rendered dozens of times with a unique key.

🎯 Quick Quiz

Question 1: Which statement best describes React?

Question 2: What is the main benefit of the Virtual DOM?

Question 3: In React, how does data normally flow between components?

Summary & Quiz

πŸŽ‰ Key Takeaways

  • React is a library, not a framework β€” it renders UI and leaves the rest of the stack to you.
  • Its pillars are components, declarative rendering, the Virtual DOM, one-way data flow, and JSX.
  • The Virtual DOM diffs an in-memory tree to apply the smallest possible real DOM update.
  • The ecosystem (Router, TanStack Query, Zustand, Next.js) fills the gaps around React's core.
  • Learning to see a UI as a tree of reusable components is the foundational React skill.

πŸ“š Further Reading

πŸš€ What's Next?

Now that you know what React is and why it works the way it does, it's time to build. In the next lesson we'll set up a real React development environment with Node.js and Vite so you can run your first app.

πŸŽ‰ Great start!

You can now explain React to someone else β€” and that's the surest sign you understand it. Let's get it running on your machine.