Next.js

The leading React framework: App Router, layouts, Server Components, data fetching and caching, Server Actions and middleware.

Intermediate · about 14 hours · difficulty 4/5

Learn first: CSR, SSR, SSG, ISR and Streaming, React Server Components and Server Actions

Next.js is the most widely used React framework and the one most job listings ask for. It adds file-based routing, server rendering, Server Components, data fetching, image and font optimisation and API endpoints on top of React.

App Router essentials

  • File-based routing in app/: folders are URL segments; page.tsx renders a route; layout.tsx wraps children and persists across navigation; loading.tsx and error.tsx add Suspense and error boundaries automatically; not-found.tsx handles 404s.
  • Dynamic segments ([slug]), route groups ((marketing)) and parallel or intercepting routes for advanced layouts.
  • Server Components by default: fetch data in async components; add "use client" for interactive parts.
  • Server Actions for mutations from forms, and Route Handlers (route.ts) for API endpoints and webhooks.
  • Middleware (proxy) runs before requests for redirects, auth checks and rewrites.

Rendering and caching

Routes are static unless they use dynamic data (cookies, headers, uncached fetches). Understand how your Next.js version caches fetch results and rendered routes, and use revalidation (revalidatePath, revalidateTag or time-based) after mutations. Read the caching docs for your exact version; the defaults have changed across releases.

Built-ins

next/image (responsive, lazy images), next/font (self-hosted fonts with no layout shift), next/link (prefetching), the Metadata API for SEO and Open Graph.

Pitfalls

Marking whole trees "use client", leaking secrets by importing server code into client components (use server-only), forgetting to authorise inside Server Actions and not knowing what is cached.

Good enough to move on

You can build and deploy a Next.js app with nested layouts, static and dynamic routes, server-side data fetching, a validated Server Action, loading and error states, and correct metadata.

Key concepts

  • App Router file conventions
  • Layouts, loading and error files
  • Dynamic routes and route groups
  • Data fetching in Server Components
  • Caching and revalidation
  • Server Actions and Route Handlers
  • Middleware
  • next/image, next/font and Metadata
  • Pages Router: Older API still found in many codebases

Other options for this step

  • React Router Framework Mode (Remix): Web-standards-first full-stack React with loaders, actions and nested routes; the evolution of Remix.
  • Nuxt: The full-stack framework for Vue: file-based routing, SSR and SSG, auto-imports, data fetching and server routes.
  • Astro: A content-first framework that ships zero JavaScript by default and hydrates interactive islands built with any UI library.
  • SvelteKit: The official Svelte application framework with file-based routing, load functions, form actions and flexible rendering.

Mini project

Build a job board in Next.js: statically generated company pages with revalidation, a dynamic search page using search params, an authenticated dashboard with Server Actions to post jobs, and SEO metadata per job.

Check yourself

You add a job with a Server Action but the list page still shows old data. What mechanism do you use to fix it?

Free resources