React is a library for building interfaces: it describes what appears on screen based on some state. It doesn't decide how URLs map to screens, where data is fetched, which machine runs each component, or how the result reaches the browser. Every project has to solve all of that on its own, and for years the usual answer was the same: a single-page application that is assembled entirely in the browser and talks to a separate API.

Next.js is a framework that makes those decisions for you. It uses React for the interface and adds what's missing to ship a complete web product: routing, server rendering, data access, caching, mutations, HTTP endpoints, asset optimization and a build process that ties it all together.

In this lesson you'll see which problems motivate that shift, which pieces Next.js provides and when it isn't the best choice. You won't install anything yet: the goal is that, when you create the project in the next lesson, you'll know why each of its parts exists.

  1. The limits of a single-page application

Picture a page that lists a city's upcoming concerts, written as an SPA (single-page application) with React:

import { useEffect, useState } from 'react'

interface AgendaEvent {
  id: string
  title: string
}

export function EventList() {
  const [events, setEvents] = useState<AgendaEvent[] | null>(null)
  const [error, setError] = useState(false)

  useEffect(() => {
    fetch('https://api.agendaviva.example/events')
      .then((response) => response.json())
      .then(setEvents)
      .catch(() => setError(true))
  }, [])

  if (error) return <p>The events could not be loaded.</p>
  if (!events) return <p>Loading…</p>

  return (
    <ul>
      {events.map((event) => (
        <li key={event.id}>{event.title}</li>
      ))}
    </ul>
  )
}

The component is correct, and yet the result has four problems that better code won't fix, because they stem from where and when it runs.

1.1. The first load is a chain of waits

The server delivers a practically empty HTML document (<div id="root"></div>). To show a concert title, the browser has to complete several steps in sequence:

sequenceDiagram
    participant N as Browser
    participant S as File server
    participant A as API
    N->>S: GET /
    S-->>N: Empty HTML
    N->>S: GET app.js
    S-->>N: Application JavaScript
    Note over N: Parse and run JS,<br/>mount React, run useEffect
    N->>A: GET /events
    A-->>N: JSON with the events
    Note over N: The list is finally painted

The data request can't start until the JavaScript has been downloaded and executed. Every hop pays the user's network latency, which can be high on a phone, and if a child component fetches its own data when it mounts, the chain gets longer. This is called a request waterfall.

On top of that, the JavaScript payload grows with the application. The library that formats dates or converts Markdown is shipped to the browser even though its output is text that will never change.

1.2. The content isn't in the HTML

A search engine, a link-preview reader or any program that requests the URL gets that empty HTML. Some crawlers run JavaScript, but not all of them do, and not always right away; and the ones that generate the card when you share a link on a social network or in a messaging app usually just read the tags in the initial HTML. For a cultural events guide, which depends on being found and shared, that's a business problem.

1.3. Data is managed by hand

With useEffect and useState you have to handle, on every screen, loading, errors, responses that arrive out of order, duplicate requests, caching and cache invalidation. Client-side data libraries improve this a lot, but they don't remove the underlying fact: data is requested from the point farthest from where it lives.

1.4. You need a separate backend

The browser can't connect to the database or keep a secret key, so a second project exists: the API. That means another deployment, contracts to keep in sync, CORS configuration and endpoints whose only client is your own interface. For many teams that separation is necessary; for others it's a cost that gives nothing back.

SPA problem Root cause What's needed
Slow first load Everything starts after the JavaScript is downloaded Send HTML with content
Poor SEO and previews The initial HTML is empty Render before the browser responds
Waterfalls and repeated loading code Data is fetched from the client Read it on the server, next to the component
An API just for your own interface The browser isn't a trusted environment Server code in the same project

  1. What a framework is and what Next.js adds

The difference between a library and a framework comes down to who calls whom. In an SPA, your code boots React and invokes it. In Next.js you write files with agreed-upon names and shapes, and the framework decides when to run them: at build time, when a request comes in or during navigation.

These are the pieces it provides, grouped by the need they cover. Each one gets its own module in the course; here the point is to see how they fit together.

Need What Next.js offers Covered in
Map URLs to screens Folder-based routing, nested layouts, loading and error states Module 2
Run components on the server React Server Components, with Client Components where interaction is needed Module 3
Read data async components that query the source directly, and streaming Module 4
Avoid repeating work Prerendering and declarative caching with 'use cache' Module 5
Modify data Server Actions and forms Module 6
Expose HTTP Route Handlers and proxy.ts Module 7
Protect the application Cookies, headers and code that never leaves the server Module 8
Polish delivery Images, fonts, metadata, prefetching and code splitting Modules 9 and 10

2.1. Routes from folders

In Next.js you don't declare a route table. A folder inside app/ is a segment of the URL, and a page.tsx file makes it visible. That structure also gives you shared layouts, per-route JavaScript splitting and link prefetching, because the framework knows every route before the application runs.

2.2. Server Components

This is the most far-reaching change. React Server Components are components that run only on the server (or at build time). They can be async, read from a database and use secrets, and their code isn't part of the JavaScript sent to the browser: what travels is their output.

Here's the same list from the beginning, written as a Server Component:

import { Suspense } from 'react'
import { listUpcomingEvents } from '@/lib/data/events'

async function EventList() {
  const events = await listUpcomingEvents()

  return (
    <ul>
      {events.map((event) => (
        <li key={event.id}>{event.title}</li>
      ))}
    </ul>
  )
}

export default function EventsPage() {
  return (
    <>
      <h1>Upcoming events</h1>
      <Suspense fallback={<p>Loading…</p>}>
        <EventList />
      </Suspense>
    </>
  )
}

What has changed compared with the SPA version:

  • There's no state or effect. The component waits for its data with await, like any asynchronous function.
  • There's no intermediate endpoint. listUpcomingEvents() can query the database: it runs on the server.
  • The HTML arrives with the content. The heading shows up immediately, and the list joins the same response once it's ready.
  • <Suspense> replaces if (!events). The wait is declared from outside the component, and in Next.js it also plays a role in prerendering that you'll see in modules 4 and 5.

Components that need state, events or browser APIs still exist: they're called Client Components and are marked with 'use client'. They're the React components you already know.

2.3. Writing data without your own API

A Server Action is a function that runs on the server and that you can attach to a form. The framework creates the request, sends it and updates the interface with the result. When you really do need an HTTP endpoint (a mobile app, a webhook, a third party), you have Route Handlers. In other words, the API stops being mandatory and becomes a choice.

2.4. Optimized by default

Next.js includes a bundler, Turbopack, and on top of it a set of improvements that you'd assemble piece by piece in an SPA: one JavaScript chunk per route, prefetching of visible links, images resized and served in modern formats, fonts hosted on your own domain and typed metadata.

  1. Where and when rendering happens

"Rendering on the server" can mean different things depending on when it happens. It's worth pinning down the vocabulary now, even though the details and the criteria for choosing belong to lesson 05-01.

Strategy When the HTML is generated Good example
Client-side (CSR) In the browser, after the JavaScript loads An interactive graphics editor
Static (prerendering) At build time, or in the background when refreshed The "About us" page
Dynamic (SSR) On the server, on every request The dashboard with the user's bookings
Partial (PPR) A shell at build time; the holes, at request time An event page with its spots left

In current versions, with the Cache Components feature enabled, the partial strategy is the App Router's default model: Next.js prerenders everything it can in each route and leaves as holes the parts that depend on uncached data or on the request. Those holes arrive via streaming in the same HTTP response.

flowchart LR
    subgraph Build
        C[next build] --> H[Static shell:<br/>header, headings, placeholders]
    end
    subgraph Request
        P[GET /events] --> E[The shell is sent<br/>immediately]
        E --> D[The server resolves<br/>the holes]
        D --> F[They stream in<br/>and replace the placeholder]
    end
    H --> E

One practical consequence: you don't choose a strategy for the whole application, or even for a whole page, but for each part of it. And another: nothing is cached unless you ask for it. Caching is declared with the 'use cache' directive on the function or component you want to reuse.

3.1. What happens after the first load

HTML coming from the server doesn't mean going back to the web of full page reloads. After the first visit, React hydrates the Client Components (it attaches their event handlers), and links navigate without reloading the document: the browser asks the server for the output of the new route's Server Components in a compact format, the RSC Payload, and React updates the screen while keeping the shared layouts.

  1. App Router and Pages Router

Next.js has two routing systems. You can tell them apart by the folder they use, and it's worth recognizing both because many of the articles and answers you'll find mix them up.

Pages Router App Router
Folder pages/ app/
Since The earliest versions Version 13 (stable in 13.4)
Components All of them are sent to the browser Server Components by default
Data fetching getServerSideProps, getStaticProps at page level await in any Server Component
Layouts _app and manual patterns Nested by convention
Partial streaming Not part of the model With <Suspense> and loading.tsx
Mutations API Routes called with fetch Server Actions
React The version in your package.json A built-in canary version, with everything stable from React 19

The Pages Router still works and can coexist with app/ in the same project, which allows gradual migrations. But the features in this course (Server Components, Server Actions, Cache Components, parallel routes) belong to the App Router, which is the recommended option for new projects. The whole course uses it.

To avoid confusion when searching for documentation: if an example mentions getServerSideProps, getStaticProps, next/router, _app.tsx or pages/api, it's for the Pages Router and won't help you here.

  1. When to choose Next.js and when not to

The React documentation recommends starting a new project with a framework and lists Next.js (App Router), React Router v7 and Expo, the latter for native apps. It also covers starting from scratch with a tool like Vite when frameworks don't fit. There's no single answer, but there are questions that narrow it down.

If your project… Reasonable option Why
Is public and depends on search engines and shared links Next.js HTML with content and per-route metadata
Mixes shared content with per-user parts Next.js Static shell with dynamic holes
Needs both an interface and a server, with a small team Next.js One project, one deployment, shared types
Is an internal tool behind a login, with an existing API Vite + React Router SEO doesn't matter and a server would be one more moving part
Is an editor or a game, almost all interaction Vite Server Components add very little
Is a widget embedded in other people's websites Vite in library mode There are no routes or pages to manage
Is a content site with very little interactivity Astro or another static site generator A simpler model for that case
Can only be hosted as static files Any of the above; Next.js with limitations Static export gives up everything that needs a server

Next.js also has costs, and it's better to know them before choosing it:

  • Two environments to keep in mind. You must always know whether a piece of code runs on the server or in the browser. It's the main hurdle when you start.
  • Conventions and fast evolution. File names carry meaning, and major versions change behavior. Caching, for example, has changed several times; lesson 05-06 explains the previous model.
  • It needs a server to get the most out of it. That can be a Node.js process, a container or a platform with an adapter, but uploading files to static storage is no longer enough.

5.1. Does it lock me into a vendor?

Next.js is maintained by Vercel, a company that also sells hosting, so the question is a fair one. According to the documentation, a Node.js server and a Docker container support every feature; static export supports only part of them; and there's a public adapter API for other platforms, with varying support. In module 11 we'll deploy the application both ways: on a managed platform and on our own server.

  1. Versions and release cycle

This course uses Next.js 16.4 with React 19. Knowing how versions are released helps you decide when to upgrade and judge whether an example you come across is still valid.

  • Stable channel (latest): the versions used in production.
  • canary channel: pre-release versions, published daily. Not recommended for production.
  • Active LTS: the latest major version. It gets new features, fixes and security patches.
  • Maintenance LTS: the previous major version. It gets critical and security fixes, in principle for up to two years after its initial release.
Major version Released Status as of December 2026
16 October 21, 2025 Active LTS
15 October 21, 2024 Maintenance LTS; security patches until January 31, 2027
14 and earlier — Unsupported

Within version 16, a few dates explain why you'll see different examples: Cache Components arrived in 16.0, partial route prefetching in 16.3, and since 16.4 new projects ship with both enabled using the recommended values. They're expected to become the default behavior in version 17, so what you learn here isn't an optional variant but the direction the framework is heading.

6.1. Upgrading isn't optional

A framework that runs code on the server is part of your attack surface. In December 2025 a critical vulnerability was published in the React Server Components protocol (CVE-2025-66478) that required immediate upgrades, and since July 2026 the project announces its scheduled security releases in advance. Treat patch versions as mandatory maintenance: in lesson 11-06 we'll make it part of the continuous integration process.

Common Mistakes and Tips

  • Thinking Next.js replaces React. Next.js uses React. Components, props, hooks and JSX are the same; what changes is where they run and who invokes them.
  • Confusing Server Components with SSR. SSR generates HTML from components, which are then also sent as JavaScript to be hydrated. A Server Component is neither hydrated nor sent: only its output travels. Client Components, on the other hand, can be prerendered on the server for the first load, despite their name.
  • Choosing it only for SEO. If all you need is static HTML that rarely changes, there are simpler tools. Next.js pays off when there's also data, users or mutations.
  • Following tutorials without checking the version. Before copying an example, check whether it's for the App Router or the Pages Router and which major version it was written for. A middleware.ts, a next lint or a fetch that "caches itself" gives away material older than 16.
  • Expecting everything to be cached. In the current model, data is read fresh on every request unless you declare otherwise.

Exercises

Exercise 1: choosing the tool

For each project, decide whether you'd choose Next.js, Vite with React Router or another option, and justify it in one or two sentences:

  1. A city council portal with news, informational procedures and a private area for each resident.
  2. A company's internal dashboard that consumes an existing API and is only reachable over VPN.
  3. A contact form that other websites embed with a <script> tag.
  4. A forty-page help document with no users or dynamic data.

Solution

  1. Next.js. There's public content that must be indexed and a per-user section. It's the textbook case of a static shell with dynamic holes, and the private area relies on server code in the same project.
  2. Vite + React Router. There's no SEO, the API already exists and the first load matters less behind a VPN. A Next.js server would be one more thing to operate. If the team needed to hide credentials or aggregate several APIs, Next.js would make sense again.
  3. Vite in library mode (or framework-free JavaScript). The result is a single embeddable file: there are no routes, pages or server of its own to render.
  4. A static site generator such as Astro, or Next.js with static export if the team already knows it well. With no data or users, most of what Next.js offers would go unused.

What matters isn't getting a fixed answer right, but backing it with criteria: public or private, per-user data, an existing backend and the hosting model.

Exercise 2: identifying the rendering strategy

An event page shows: the site header, the concert's title and description, the number of spots left right now, a greeting with the user's name and a button to save the event to favorites that changes color when clicked. For each part, state whether it should be generated ahead of time, resolved at request time or whether it needs to run in the browser.

Solution

  • Header: ahead of time. It doesn't depend on data or on the user.
  • Title and description: ahead of time or from the cache. They're the same for everyone and rarely change; they'll need data cached with 'use cache' (module 5).
  • Spots left: at request time, via streaming. They change with every booking, and a stale value would be misleading.
  • Greeting: at request time. It depends on the session cookie, which doesn't exist at build time.
  • Favorites button: Client Component. It responds to an event and has state. Its initial HTML can come from the server, but its behavior needs JavaScript.

A single page combines three different treatments. That's partial rendering.

Exercise 3: spotting outdated material

You come across a tutorial with this code. Point out the clues that it belongs to a different model or to an earlier version of Next.js.

import { useRouter } from 'next/router'

export async function getServerSideProps() {
  const response = await fetch('https://api.example.com/events')
  const events = await response.json()
  return { props: { events } }
}

export default function Page({ events }) {
  const router = useRouter()
  return <p onClick={() => router.push('/')}>{events.length} events</p>
}

Solution

There are two conclusive clues that this is Pages Router code: getServerSideProps, which doesn't exist in the App Router, and useRouter imported from next/router (in the App Router it comes from next/navigation and can only be used in Client Components).

It's also telling that a single component receives data from the server and handles onClick: in the Pages Router that's normal, because every component is sent to the browser. In the App Router it would be split up: a Server Component that reads the data and a small Client Component for the interaction. Besides, the right way to navigate to another page would be a link, not a paragraph with onClick.

Conclusion

An SPA leaves all the work to the browser, which is why the first load is a chain of waits, the HTML arrives empty and you need an API just to feed the interface. Next.js moves to the server whatever can be done there: routes by convention, Server Components that read data, actions that modify it and rendering that combines a static shell with dynamic parts on the same page. In return, it asks you to think in two environments and to accept its conventions, so it isn't worth it for every project.

You now have the map. In the next lesson, Creating the Project and Development Tools, you'll generate the course project with the recommended values and get to know the tools you'll use every day.

© Copyright 2026. All rights reserved