Framework Guide
What Is Next.js?
Next.js is the framework that turned React into a full production stack. It adds routing, server rendering, and everything you need to ship real apps. Here's what makes it different.
Quick answer: Next.js is a React framework that gives you file-based routing, server-side rendering, static generation, API routes, and image optimization out of the box. It's maintained by Vercel and used by companies like Netflix, TikTok, and Notion.
💡 Why Next.js Matters
- File-based routing. Create a file, get a page. No config, no router setup.
- Server Components. Fetch data directly in components — no useEffect, no loading state juggling.
- Built-in API routes. Add backend endpoints in the same project.
- Automatic image optimization. Resize, lazy-load, and convert formats for free.
- Deploy anywhere. Vercel, Netlify, Docker, or your own server.
- SEO-friendly. Pages render on the server, so Google sees full HTML.
⚖️ React vs Next.js
Same component code, different features around it:
Plain React (with Vite):
// You handle routing manually
import { BrowserRouter, Routes, Route } from 'react-router-dom';
// Client-only rendering
// Extra libraries for SSR, images, API, etc.
Next.js:
// File-based routing:
// app/page.jsx -> /
// app/about/page.jsx -> /about
// app/blog/[slug]/page.jsx -> /blog/:slug
// Server components by default
async function Page() {
const data = await fetch('https://api.example.com/data');
return <div>{data}</div>;
}
Less setup, more built-in features, better defaults.
🧩 Core Next.js Concepts
- App Router — folders define routes.
app/about/page.tsxbecomes/about. - Server Components — run on the server, ship no JS to the browser. The default in Next.js.
- Client Components — run in the browser. Add
"use client"at the top of the file to opt in. - API Routes —
app/api/hello/route.tsbecomes/api/hello. - Layouts — shared UI that wraps pages, like a navbar that stays on every route.
- Metadata — export a metadata object from any page for SEO tags.
📁 A Basic Next.js Project Structure
my-nextjs-app/
├── app/
│ ├── layout.tsx ← shared layout
│ ├── page.tsx ← homepage (/)
│ ├── about/
│ │ └── page.tsx ← /about
│ ├── blog/
│ │ └── [slug]/
│ │ └── page.tsx ← /blog/:slug
│ └── api/
│ └── hello/
│ └── route.ts ← /api/hello
├── public/ ← static assets
├── package.json
└── next.config.js
Every folder inside app/ becomes a URL. That's the whole routing system.
🚫 Common Beginner Mistakes
- Using Next.js before React. Learn React first — Next.js adds to it, doesn't replace it.
- Adding "use client" everywhere. That defeats the purpose. Only use it when you need interactivity.
- Trying to use browser APIs in Server Components. Things like
windoworlocalStoragedon't exist on the server. - Fetching data in useEffect. In Next.js, fetch directly in Server Components instead.
- Deploying without setting environment variables. Next.js reads
.env.locallocally but needs them configured on the host.
❓ Frequently Asked Questions
What is Next.js?
;A React framework that adds file-based routing, server-side rendering, API routes, and image optimization. It's the most popular way to build production React apps.
Do I need to know React first?
Yes. Next.js is built on React. Get comfortable with components, props, state, hooks, and JSX first.
What is the App Router?
Next.js's modern routing system (from v13). Uses folders for routes and lets you write React Server Components alongside client components.
Is Next.js better than plain React?
For anything beyond a single-page app, yes. Next.js adds features React doesn't have — routing, SSR, SSG, image optimization, API routes.
Is Next.js free?
Yes. Open source and free. Vercel offers free hosting for personal projects, but you can deploy anywhere that runs Node.js.