Skip to content
Tutorials Center
My learning

Topics

Lesson 149 of 156 ยท Practice and Review

Where to Go Next: Libraries and Frameworks

Understand React, Vue, Svelte, Angular, Solid, Next.js, Express and Hono by building tiny versions of components, reactivity and virtual DOM diffing.

You now know the JavaScript language, the DOM, asynchronous code, modules and the tooling around them. Look at job listings or open-source projects, though, and you'll see names this course hasn't taught directly: React, Vue, Svelte, Angular, Next.js, Express. Do you have to start over?

No. Every one of these tools is written in the JavaScript you already know, and they all solve the same few problems with ideas you can understand in an afternoon. This lesson maps the landscape: what frameworks are for, the three core ideas behind modern UI libraries (components, reactivity and virtual DOM diffing, each rebuilt here in a few lines of plain JavaScript), the main libraries and meta-frameworks, server frameworks, state management, build and test tools, and finally how to choose what to learn next.

What problem do frameworks solve?

In the DOM lessons you updated the page by hand: find an element, change its text, add a class, append a child. For a to-do list that's fine. For an app with hundreds of interactive pieces it becomes the main source of bugs, because every change to your data needs matching, hand-written changes to the page. Forget one and the screen shows something different from what your data says.

Modern UI libraries flip this around. You describe what the page should look like for a given state, and the library works out which DOM changes are needed whenever the state changes. That idea is often written as:

TEXT
UI = f(state)

Beyond that core, frameworks offer a consistent project structure, routing between pages, data loading, server-side rendering for speed and SEO, and an ecosystem of components and tools that teams share.

Core idea 1: components

A component is a reusable piece of UI that takes inputs (usually called props) and returns markup. Components nest inside each other like HTML elements, so a page is a tree of them: App contains Header and ProductList, which contains many ProductCards.

In plain JavaScript, a component is simply a function that returns DOM nodes. Rendering everything again from state whenever something changes keeps the screen and the data in sync automatically:

Components as plain functions

Click "Add" a few times and the cart is always right, because it's computed from state on every render. The weakness is just as visible in the code: render() throws away and rebuilds the whole app on every change. In a large app that's slow, and it destroys things the DOM keeps for you, such as the cursor position in a text field or the scroll position of a list. The next two ideas exist to fix exactly that.

Core idea 2: reactivity with signals

Reactivity means the library knows which parts of the page depend on which pieces of state, so it can update only those. The most popular way to do this today is signals: values that remember who read them. Solid is built on signals, Vue's ref() works the same way, Svelte 5's $state and Angular's signal() are signals too, and there's a proposal to add them to JavaScript itself.

Signals are a neat use of closures. Here is a working implementation in about 30 lines:

JS A signals library from scratch

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Nobody told the effects what to watch. Each signal recorded which effect read it while that effect was running, so changing quantity reruns only the code that actually used it. Real libraries add batching (several changes, one update), cleanup of old subscriptions and glitch-free ordering, but the heart is the same.

Connect effects to DOM nodes and you get fine-grained updates: when a signal changes, only the specific text node or attribute that depends on it is touched, and nothing is rebuilt.

Signals updating only what changed

Type something in the note field, then click the buttons: the input keeps its text and cursor because it is never rebuilt. The counters show each binding running only when its signal changes.

Core idea 3: the virtual DOM and diffing

React took a different road. Its components re-run and return a lightweight description of the UI: plain objects like { type: "li", props: {...}, children: [...] }, called the virtual DOM. React then diffs the new description against the previous one and applies only the differences to the real DOM. This step is called reconciliation.

JS A tiny virtual DOM diff

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The whole component re-ran, yet only four small changes would reach the real DOM: one text update in the heading, two class changes and one new list item. That's the trade-off: you write simple "render everything" code, and the diff makes it cheap enough.

Our diff compares children by position. Insert an item at the top of a list and every item seems to have changed. That's why React and Vue ask for a key prop on list items: with stable keys, the diff can match items by identity and simply move them. Use an ID from your data as the key, never the array index.

Signals or virtual DOM? Both work well. Fine-grained signals (Solid, Svelte 5, Vue's reactivity, Angular's newer APIs) skip the diffing step and tend to be faster and smaller. The virtual DOM (React, Preact, and Vue's rendering layer) gives a very simple mental model and React's huge ecosystem. For most apps, the difference in speed matters less than how you load data and how much JavaScript you ship.

The main UI libraries

Here's the same counter in three popular libraries, to show how similar the ideas are. You don't need to run these; they need each library's build tools.

JavaScript
// React: components are functions; state comes from hooks; markup is JSX
import { useState } from "react";

export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>Clicked {count} times</button>;
}
HTML
<!-- Vue: a single-file component with a template and reactive refs -->
<script setup>
import { ref } from "vue";
const count = ref(0);
</script>

<template>
  <button @click="count++">Clicked {{ count }} times</button>
</template>
HTML
<!-- Svelte 5: a compiler turns this into direct DOM updates -->
<script>
  let count = $state(0);
</script>

<button onclick={() => count++}>Clicked {count} times</button>
Library Style Known for
React Functions + JSX, hooks, virtual DOM The largest ecosystem and job market; React Native for mobile apps
Vue HTML-like templates, signals-style reactivity Gentle learning curve, excellent docs, popular in Asia and Europe
Svelte A compiler; little runtime code Small bundles, very little boilerplate
Angular A complete framework in TypeScript, with dependency injection Large enterprise apps with many teams; everything included
Solid JSX with fine-grained signals, no virtual DOM Top performance; React-like syntax
Preact, Lit, Alpine.js, htmx Lighter options Preact is a tiny React alternative; Lit builds standard web components; Alpine and htmx add interactivity to server-rendered HTML

Meta-frameworks: full apps, not just components

UI libraries render components. A real website also needs routing, data loading, server rendering, code splitting and deployment. Meta-frameworks bundle all of that on top of a UI library:

  • Next.js (React) and React Router (React; formerly Remix), Nuxt (Vue), SvelteKit (Svelte), SolidStart (Solid) and Analog (Angular).
  • Astro is built for content-heavy sites such as blogs, docs and marketing pages. It sends plain HTML by default and only loads JavaScript for interactive "islands", which can be written in React, Vue, Svelte or others.

They share a vocabulary worth knowing:

  • SSR (server-side rendering): the server runs your components and sends ready HTML, so the page appears fast and search engines can read it.
  • SSG (static site generation): the HTML is generated once at build time and served as files.
  • Hydration: the browser downloads the JavaScript and attaches event listeners to server-rendered HTML to make it interactive.
  • Islands: only the interactive parts of a page are hydrated; the rest stays static HTML.

Server-side frameworks

On the server, frameworks wrap Node's http module (see Node.js basics) with routing, middleware, body parsing and error handling:

JavaScript
// Read-only: a JSON endpoint in Hono, which uses the standard Request/Response
import { Hono } from "hono";

const app = new Hono();

app.get("/api/books/:id", async (c) => {
  const book = await db.findBook(c.req.param("id"));
  return book ? c.json(book) : c.json({ error: "Not found" }, 404);
});

export default app;
  • Express: the long-time standard, minimal and with middleware for everything. Version 5 modernized it with promise support.
  • Fastify: focused on speed, with schema-based validation and a plugin system.
  • Hono: small and built on web-standard Request/Response, so the same code runs on Node.js, Deno, Bun and edge platforms.
  • NestJS: a structured, Angular-inspired framework in TypeScript for large back ends.

State management

Where should data live? Start with the simplest answer that works:

  1. Component state for data one component uses (an open menu, a form field).
  2. Lifting state up to a shared parent when siblings need the same data, and context (React) or provide/inject (Vue) to pass it deep without threading props through every level.
  3. A store when many distant parts of the app read and change the same data. The patterns behind the popular stores are simple, as this reducer-based store shows:
JS A tiny store with reducers and subscribers

Press Run (or Ctrl + Enter) to see the console output here.

No output.

That's the idea behind Redux (today used through Redux Toolkit), while Zustand, Jotai (React) and Pinia (Vue) offer lighter APIs on the same theme. Returning new objects instead of mutating (see Copying Objects) is what lets libraries detect changes with a cheap === check. Data that comes from a server is a special case: TanStack Query and similar libraries cache it, refetch it and track loading and error states for you, which removes much of what people used to put into global stores.

Build tools and testing

Frameworks rely on the tools from Packages, npm and Build Tools:

  • Vite is the default dev server and build tool for most new projects (Vue, Svelte, Solid, React and Astro all use it). It's moving to Rolldown, a fast bundler written in Rust. esbuild, Rollup, webpack, Rspack and Turbopack (used by Next.js) are the other names you'll meet.
  • TypeScript is used by most professional framework projects; this site has a full TypeScript tutorial.
  • For tests (see Testing): Vitest or Jest for unit tests, Testing Library for testing components the way users use them, and Playwright or Cypress for end-to-end tests in real browsers.

How to choose what to learn

There's no single best framework, but there are good reasons to pick one:

  • For a job: look at listings in your area. React is the most requested almost everywhere, with Angular strong in large companies and Vue in many regions.
  • For a content site (blog, docs, marketing): Astro, or plain HTML with a little JavaScript.
  • For an interactive app: React with Next.js, Vue with Nuxt, or Svelte with SvelteKit are all excellent and well supported.
  • For a large organization with many teams: Angular's all-in-one structure (or React with strict conventions).
  • For adding interactivity to a server-rendered site (Laravel, Rails, Django): Alpine.js or htmx may be all you need.

Whatever you pick, the advice is the same: build something real with it, read its official tutorial, and keep your vanilla JavaScript sharp. Frameworks change every few years. Closures, promises, the event loop, the DOM and clean functions don't, and they're what make you good at every framework.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the formula UI = f(state) describe?

    You describe what the UI should be for any state; the library figures out the DOM changes.
  2. 2. How does a signal know which effects to rerun when it changes?

    Reading a signal inside a running effect subscribes that effect, so a write reruns only the code that used the value.
  3. 3. What is the virtual DOM?

    Components return cheap plain objects; reconciliation compares old and new trees and applies only the differences.
  4. 4. Why do React and Vue ask for a key on list items?

    Matching by position makes an insert at the top look like every item changed. Use a stable ID, not the array index.
  5. 5. You're building a documentation site that is mostly static text with a few interactive widgets. Which tool fits best?

    Content sites benefit from static HTML with JavaScript only where needed, which is exactly what islands provide.

Summary

  • Frameworks keep the screen in sync with your data: you describe UI = f(state) and the library updates the DOM.
  • Components are reusable functions (or classes) from props to UI; pages are trees of components.
  • Signals track which code read which value and update only what depends on a change (Solid, Vue, Svelte 5, Angular).
  • The virtual DOM re-renders cheap object trees and diffs them (React, Preact); give list items stable keys.
  • Meta-frameworks (Next.js, Nuxt, SvelteKit, Astro) add routing, data loading, SSR, SSG and hydration.
  • On the server, Express, Fastify, Hono and NestJS build on Node's HTTP module.
  • Keep state local first; use a store (Redux Toolkit, Zustand, Pinia) for widely shared data and TanStack Query for server data.
  • Pick a framework for your goals, build something real, and keep your core JavaScript strong.

Next: JavaScript Cheat Sheet โ€” the whole language on one page for quick review.