Skip to main content

Next.js

Next.js is a React framework that enables server-side rendering, static site generation, and full-stack development. Created by Vercel, it's become the de facto standard for production React applications.

Key Features

  • Hybrid rendering: SSR, SSG, ISR, and client-side in one app
  • File-based routing: Pages defined by file structure
  • API routes: Backend endpoints alongside frontend
  • Image optimisation: Automatic image handling
  • Zero config: Works out of the box

Rendering Methods

MethodWhenBest For
SSG (Static)Build timeBlogs, marketing pages
SSR (Server)Request timeDynamic, personalised content
ISR (Incremental)BackgroundLarge sites with frequent updates
CSR (Client)BrowserHighly interactive parts

App Router (Next.js 13+)

app/
├── layout.tsx # Root layout
├── page.tsx # Home page (/)
├── about/
│ └── page.tsx # About page (/about)
├── blog/
│ ├── page.tsx # Blog index (/blog)
│ └── [slug]/
│ └── page.tsx # Blog post (/blog/my-post)
└── api/
└── users/
└── route.ts # API endpoint (/api/users)

Server Components

// This runs on the server by default
async function ProductPage({ params }) {
const product = await db.product.findUnique({
where: { id: params.id },
});

return (
<div>
<h1>{product.name}</h1>
<AddToCart id={product.id} /> {/* Client component */}
</div>
);
}

What We Like

  • Developer experience: Fast refresh, excellent error handling
  • Performance: Automatic optimisations, Edge runtime
  • Full-stack: Frontend and API in one codebase
  • Vercel integration: Seamless deployment
  • Active development: Regular updates and improvements

What We Don't Like

  • Complexity: Many rendering modes to understand
  • Vercel-centric: Some features work best on Vercel
  • App Router learning curve: Significant shift from Pages Router
  • Build times: Can be slow for large sites
  • Vendor lock-in concerns: Increasingly tied to Vercel

Next.js vs Nuxt

AspectNext.jsNuxt
FrameworkReactVue
RenderingSSR, SSG, ISRSSR, SSG
API routesBuilt-inNitro server
DeploymentVercel optimisedUniversal
Learning curveSteeperGentler

When to Use Next.js

  • Production React applications
  • SEO-critical websites
  • E-commerce storefronts
  • Marketing sites with dynamic features
  • Full-stack React projects