CoachnestCoachnest
Sign InGet Started
Back to course

Next.js 16: The Complete Developer Guide

…
—
Contents
1

What's New in Next.js 16

Reading14mFree
2

Installation, CLI & Your First Project

Reading12mFree
3

Project Structure & Conventions Deep Dive

Reading16m
4

Turbopack — The New Default Bundler

Video18m
5

Configuring TypeScript, ESLint & next.config.ts

Reading14m
6

Chapter 1 — Quiz

Quiz10m
7

App Router Fundamentals

Reading16m
8

Dynamic Routes, Catch-Alls & Type-Safe Params

Reading14m
9

Route Groups & Parallel Routes

Reading16m
10

Intercepting Routes & Modal Patterns

Reading12m
11

Loading, Error & Not-Found UI

Reading12m
12

Chapter 2 — Routing Quiz

Quiz12m
13

Understanding the Server/Client Boundary

Reading18m
14

Choosing When to use "use client"

Reading14m
15

Composing Server & Client Components

Reading14m
16

server-only, client-only & Code Splitting

Reading12m
17

Chapter 3 — Quiz

Quiz10m

Fetching Data in Server Components

Reading14m
19

The Next.js 16 Cache Model

Reading16m
20

Revalidation: revalidateTag, revalidatePath & On-Demand

Reading12m
21

Cache Components — Building Reusable Cached Functions

Reading14m
22

Search Params, Cookies & Dynamic APIs

Reading12m
23

Chapter 4 — Quiz

Quiz12m
24

Server Actions From First Principles

Reading16m
25

Forms with useActionState & Progressive Enhancement

Reading14m
26

Optimistic UI with useOptimistic

Reading12m
27

Validation with Zod + Server Actions

Reading12m
28

Chapter 5 — Quiz

Quiz10m
29

Static vs Dynamic vs Streaming

Reading14m
30

generateStaticParams & Pre-Rendering Dynamic Routes

Reading12m
31

Incremental Static Regeneration (ISR)

Reading12m
32

Partial Prerendering (PPR)

Reading16m
33

Edge Runtime vs Node.js Runtime

Reading12m
34

Rendering Strategies Deep Dive

Video22m
35

Chapter 6 — Quiz

Quiz12m
36

Tailwind CSS v4 with Next.js 16

Reading14m
37

CSS Modules, Global Styles & Scoped CSS

Reading10m
38

next/image — Smart, Fast Images

Reading14m
39

Fonts, Icons & Metadata

Reading12m
40

Chapter 7 — Quiz

Quiz10m
41

Middleware Fundamentals

Reading14m
42

Sessions, JWTs & Cookies

Reading16m
43

Protecting Server Components & Server Actions

Reading12m
44

Chapter 8 — Quiz

Quiz10m
45

Prisma with Next.js — The Production Setup

Reading14m
46

Mutations: Server Actions + Database Writes

Reading12m
47

Route Handlers & REST APIs

Reading12m
48

Chapter 9 — Quiz

Quiz10m
49

Unit & Component Testing with Vitest

Reading12m
50

End-to-End Testing with Playwright

Reading14m
51

Deploying to Vercel

Reading12m
52

Self-Hosting with Docker

Reading14m
53

Production Performance Checklist

Reading12m
54

Final Assessment — Next.js 16 Mastery

Quiz20m
←→navigate lessons
Chapter 4 of 10·Chapter 4 — Data Fetching & The Next.js 16 Cache Model
Lesson 18 of 54Reading14 min

Fetching Data in Server Components

#Fetching Data in Server Components¶

In Next.js 16 the simplest, fastest, most-cacheable way to load data is to call fetch (or your DB client) directly inside a async Server Component.

The Basic Pattern¶

tsx
13 lines
1// app/courses/page.tsx
2export default async function CoursesPage() {
3  const res = await fetch("https://api.coachnest.dev/courses");
4  const courses: Course[] = await res.json();
5
6  return (
7    <ul>
8      {courses.map((c) => (
9        <li key={c.id}>{c.title}</li>
10      ))}
11    </ul>
12  );
13}

No useEffect. No loading flicker on the client. The HTML arrives populated.

With a Database Client¶

tsx
11 lines
1import { db } from "@/lib/db";
2
3export default async function CoursesPage() {
4  const courses = await db.course.findMany({
5    where: { status: "PUBLISHED" },
6    select: { id: true, title: true, slug: true },
7    orderBy: { createdAt: "desc" },
8  });
9
10  return courses.map((c) => <CourseCard key={c.id} course={c} />);
11}

Parallel Fetches¶

Avoid waterfalls — request things in parallel.

tsx
6 lines
1// ❌ Serial — 2 round trips back-to-back
2const user   = await getUser(id);
3const orders = await getOrders(id);
4
5// ✅ Parallel — both fire at the same time
6const [user, orders] = await Promise.all([getUser(id), getOrders(id)]);

Nested Data: Lift the Fetch¶

Suspense + multiple Server Components let you stream independent regions:

tsx
12 lines
1export default function Dashboard() {
2  return (
3    <>
4      <Suspense fallback={<EarningsSkeleton />}>
5        <Earnings />     {/* its own async server component, own DB call */}
6      </Suspense>
7      <Suspense fallback={<StudentsSkeleton />}>
8        <Students />
9      </Suspense>
10    </>
11  );
12}

The browser sees one or the other render as data arrives — TTFB is dictated by the fastest fetch, not the slowest.

Deduplication¶

Multiple components in the same render that call fetch() with the same URL & options share a single network request:

tsx
6 lines
1async function getMe() {
2  const res = await fetch("/api/me");
3  return res.json();
4}
5
6// Both call getMe() in the same render — only ONE network request fires.

For non-fetch deduplication, wrap helpers with React's cache():

ts
5 lines
1import { cache } from "react";
2
3export const getUser = cache(async (id: string) => {
4  return db.user.findUnique({ where: { id } });
5});

Forwarding Cookies & Headers¶

ts
4 lines
1import { cookies, headers } from "next/headers";
2
3const session = (await cookies()).get("session")?.value;
4const ua = (await headers()).get("user-agent");

In Next.js 16 cookies() and headers() are asynchronous — always await them.

Calling External APIs With Auth¶

ts
3 lines
1const res = await fetch("https://api.example.com/v1/users", {
2  headers: { Authorization: `Bearer ${process.env.API_TOKEN}` },
3});

The token never reaches the client. The fetch happens server-side, full stop.

Error Handling¶

tsx
8 lines
1const res = await fetch("/api/something");
2
3if (!res.ok) {
4  if (res.status === 404) notFound();
5  throw new Error(`API failed: ${res.status}`);
6}
7
8const data = await res.json();

notFound() and redirect() are special — they don't throw user-visible errors, they unwind to the routing layer.

Previous

Chapter 3 — Quiz

Next

The Next.js 16 Cache Model

Use ← → arrow keys to navigate between lessons