Skip to content

Next.js โ€” React Framework Training

Last reviewed: 2026-05-29

Next.js is a React meta-framework created by Vercel that provides server-side rendering (SSR), static site generation (SSG), API routes, file-based routing, and full-stack capabilities out of the box. It's the recommended framework for production React applications.


Overview

Next.js extends React with: - File-based routing โ€” Pages in app/ or pages/ automatically become routes - App Router (Next.js 13+) โ€” New routing paradigm with React Server Components - Rendering strategies โ€” SSR, SSG, ISR (Incremental Static Regeneration) - API routes โ€” Build backend endpoints alongside frontend - Middleware โ€” Edge-level request interception - Image optimization โ€” Built-in <Image> component - Font optimization โ€” next/font for self-hosted Google Fonts - Turbopack โ€” Rust-based bundler (faster builds)


Training Content


App Router (Next.js 13+)

app/
โ”œโ”€โ”€ layout.tsx          # Root layout (wraps all pages)
โ”œโ”€โ”€ page.tsx            # Home page "/"
โ”œโ”€โ”€ about/
โ”‚   โ””โ”€โ”€ page.tsx        # /about
โ”œโ”€โ”€ blog/
โ”‚   โ”œโ”€โ”€ layout.tsx      # Blog section layout
โ”‚   โ”œโ”€โ”€ page.tsx        # /blog (list)
โ”‚   โ””โ”€โ”€ [slug]/
โ”‚       โ””โ”€โ”€ page.tsx    # /blog/:slug (dynamic route)
โ””โ”€โ”€ api/
    โ””โ”€โ”€ hello/
        โ””โ”€โ”€ route.ts    # API endpoint /api/hello

Server vs Client Components

// Server Component (default in App Router)
// Can be async, direct DB access, no hooks
async function BlogList() {
  const posts = await db.posts.findMany();
  return <ul>{posts.map(p => <li>{p.title}</li>)}</ul>;
}

// Client Component โ€” add "use client" directive
// When you need interactivity, hooks, browser APIs
"use client";
function LikeButton() {
  const [liked, setLiked] = useState(false);
  return <button onClick={() => setLiked(!liked)}>โ™ฅ</button>;
}

Data Fetching (App Router)

// Fetch at request time (dynamic)
async function Page() {
  const data = await fetch('https://api.example.com/data');
  return <div>{/* render data */}</div>;
}
  • Static by default โ€” fetch() defaults to cache: 'force-cache'
  • Dynamic โ€” cache: 'no-store' or next: { revalidate: 60 } for ISR
  • Server Components fetch directly โ€” no useEffect needed for data

Key Features

Feature Description
SSR Render on each request (dynamic content)
SSG Pre-build at build time (fast, cached)
ISR Re-generate pages periodically (stale-while-revalidate)
Middleware Edge functions for redirects, auth, i18n
Route Handlers Full HTTP API endpoints in app/api/
Server Actions Form submissions without manual API routes

Resources