Skip to main content
  1. Posts/

Next.js Complete Guide: The King of React Full-Stack Frameworks

sun.ao
Author
sun.ao
I’m sun.ao, a programmer passionate about technology, focusing on AI and digital transformation.
Table of Contents

If React is the king of frontend UI, then Next.js is the “magic tool” that takes React to full-stack. It allows React to do more than just SPA (Single Page Applications)—it enables SSR (Server-Side Rendering), APIs, Edge Functions, and more.

What is Next.js?
#

Next.js is a React full-stack framework built by Vercel (formerly Zeit), released in 2016. It builds a layer of abstraction on top of React, providing server-side rendering, static generation, and API routing capabilities.

Understanding Through Analogy
#

AspectPlain ReactNext.js
Page renderingClient-side rendering (CSR)Supports SSR, SSG, ISR
RoutingNeed React RouterFile-system routing (automatic)
APINeed to build separatelyBuilt-in API Routes
SEOPoor (needs extra work)Naturally SEO-friendly
LikeA car with only an engineA complete car

Core Features
#

1. Multiple Rendering Modes: Choose as Needed
#

Next.js supports various rendering strategies, allowing you to choose the most appropriate one for each scenario:

Client-Side Rendering (CSR)
#

Traditional React rendering approach, pages generated in the browser.

// app/page.js (App Router)
'use client';

import { useState, useEffect } from 'react';

export default function Page() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch('/api/data').then(res => res.json()).then(setData);
  }, []);

  return <div>{data ? data.message : 'Loading...'}</div>;
}

Server-Side Rendering (SSR)
#

Pages are rendered on the server, regenerated on each request.

// app/page.js
async function getData() {
  const res = await fetch('https://api.example.com/data', {
    cache: 'no-store'  // Re-fetch on every request
  });
  return res.json();
}

export default async function Page() {
  const data = await getData();

  return <div>{data.message}</div>;
}

Static Site Generation (SSG)
#

Pages are generated at build time, built once, cached forever.

// app/blog/[slug]/page.js
async function getPost(slug) {
  const res = await fetch(`https://api.example.com/posts/${slug}`);
  return res.json();
}

export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts').then(r => r.json());
  return posts.map((post) => ({ slug: post.slug }));
}

export default async function PostPage({ params }) {
  const post = await getPost(params.slug);
  return <article>{post.content}</article>;
}

Incremental Static Regeneration (ISR)
#

Pages are statically generated but can be updated periodically.

// Revalidate every 60 seconds
export const revalidate = 60;

async function getData() {
  const res = await fetch('https://api.example.com/data');
  return res.json();
}

export default async function Page() {
  const data = await getData();
  return <div>{data.content}</div>;
}

2. App Router: The New Routing System
#

Next.js 13+ introduced the App Router, a completely new routing and rendering paradigm:

app/
├── page.js              // Home page (/)
├── layout.js            // Root layout
├── blog/
│   ├── page.js          // /blog
│   └── [slug]/
│       └── page.js      // /blog/:slug
└── api/
    └── route.js         // /api/* API routes

Role of layout.js:

// app/layout.js
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <nav>Navigation</nav>
        <main>{children}</main>
        <footer>Footer</footer>
      </body>
    </html>
  );
}

Layouts automatically wrap child pages and don’t re-render during page transitions—this is “persistent layouts.”

3. Server Components: Server-Side Components
#

A major innovation of App Router is the default use of Server Components:

// This is a Server Component (default)
async function BlogPost({ id }) {
  // Directly access data on the server
  const post = await db.posts.find(id);
  return <article>{post.content}</article>;
}

Benefits of Server Components:

  • Reduce client-side JavaScript bundle size
  • Directly access backend resources (databases, file systems)
  • Automatic code splitting
  • Better SEO

4. API Routes: Built-in Backend
#

Next.js allows you to write APIs directly in your project:

// app/api/user/route.js
import { NextResponse } from 'next/server';

export async function GET() {
  const users = await db.users.findMany();
  return NextResponse.json(users);
}

export async function POST(request) {
  const body = await request.json();
  const user = await db.users.create(body);
  return NextResponse.json(user, { status: 201 });
}

5. Image and Font Optimization
#

Next.js has built-in optimization features:

import Image from 'next/image';
import { Inter } from 'next/font/google';

// Optimized font
const inter = Inter({ subsets: ['latin'] });

export default function Page() {
  return (
    <main className={inter.className}>
      {/* Optimized image - auto format conversion, lazy loading */}
      <Image
        src="/hero.jpg"
        alt="Hero"
        width={800}
        height={600}
        priority  // Preload critical above-the-fold images
      />
    </main>
  );
}

Why is Next.js So Popular?#

1. Full-Stack Capabilities
#

Next.js enables React developers to:

  • Frontend: Build UI components
  • Backend: Write API Routes
  • Database: Access directly (via Server Components)
  • Deployment: One-click deploy to Vercel

2. Performance Optimization
#

Next.js does a lot of performance optimization:

  • Automatic code splitting
  • Image optimization
  • Font optimization
  • Prefetching
  • Caching strategies

3. SEO-Friendly
#

Server-side rendering and static generation make SEO simple:

  • Search engines can crawl complete HTML directly
  • Meta tags are easy to configure
  • Open Graph images are auto-generated

4. Rich Ecosystem
#

  • Officially maintained by Vercel
  • Synchronized updates with React
  • Many community plugins
  • Complete documentation and examples

Use Cases
#

ScenarioSuitabilityNotes
Marketing websites⭐⭐⭐⭐⭐SSG + ISR, excellent performance
Blogs / Content sites⭐⭐⭐⭐⭐SSG, SEO-friendly
SaaS products⭐⭐⭐⭐⭐SSR + CSR hybrid
E-commerce sites⭐⭐⭐⭐⭐ISR, balance of performance and updates
Corporate websites⭐⭐⭐⭐⭐Static generation, fast loading
API backend⭐⭐⭐⭐API Routes are lightweight enough

Learning Path
#

Beginner (1-2 weeks)
#

  1. Understand Next.js project structure
  2. Master App Router basics
  3. Learn pages and layouts
  4. Understand the difference between SSR, SSG, and CSR

Intermediate (2-3 weeks)
#

  1. Deep dive into Server Components
  2. Master data fetching (fetch, Server Actions)
  3. Learn API Routes
  4. Understand route groups and middleware

Advanced (continuous learning)
#

  1. Performance optimization techniques
  2. Vercel deployment
  3. Edge Functions
  4. Deep dive into caching mechanisms

Next.js 14/15 New Features
#

FeatureDescription
Server ActionsExecute functions on the server, call like regular functions
Partial PrerenderingHybrid rendering approach for static and dynamic
TurbopackRust-based bundler, 10x faster than Webpack
Serial streamingMore granular streaming rendering control

Comparison with Other Frameworks
#

FeatureNext.jsNuxt (Vue)Remix
Framework baseReactVueReact
Rendering modesSSR/SSG/CSRSSR/SSG/CSRSSR (default)
RoutingFile-systemFile-systemFile-system
APIBuilt-inBuilt-inNested routes
DeploymentVercel (native)Any platformAny platform
Ease of start⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐

Simply put:

  • Next.js: Best full-stack solution in the React ecosystem, backed by Vercel
  • Nuxt: Full-stack choice for Vue developers
  • Remix: More modern web standards理念, slightly steeper learning curve

Summary
#

Next.js extends React from a frontend library to a complete full-stack framework:

  1. Multiple rendering modes—SSR, SSG, ISR, choose as needed
  2. App Router—Modern routing and layout system
  3. Server Components—Reduce client code, improve performance
  4. API Routes—Frontend and backend integrated development
  5. Vercel ecosystem—One-click deployment, ultimate experience

If you use React, Next.js is almost essential to learn. It not only improves development experience but also brings better performance and user experience.


Next up: Next.js takes the “React full-stack” route, while Astro takes a completely different approach—“static first”—achieving zero JavaScript output with its “Islands architecture.” Let’s dive into this “performance king” in the next article.

Related articles