The React Framework for the Web
The React framework for production. Build full-stack web apps with server rendering, file-based routing, and a first-class developer experience.
A guided path from the fundamentals up. Tick off steps as you go.
The core mental model: routing, components, and data — the 20% that unlocks 80% of Next.js.
// app/blog/[slug]/page.tsx
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <h1>Post: {slug}</h1>
}'use client'
import { useState } from 'react'
export function Counter() {
const [n, setN] = useState(0)
return <button onClick={() => setN(n + 1)}>Clicked {n}</button>
}export default async function Page() {
const res = await fetch('https://api.example.com/posts')
const posts = await res.json()
return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>
}import Link from 'next/link'
<Link href="/blog/hello">Read the post</Link>// component.module.css
.card { padding: 1rem; border-radius: 8px; }
// Component.tsx
import styles from './component.module.css'
export default () => <div className={styles.card}>Hi</div>// app/dashboard/layout.tsx
export default function Layout({ children }: { children: React.ReactNode }) {
return <section><Sidebar />{children}</section>
}// app/dashboard/loading.tsx
export default function Loading() {
return <p>Loading your dashboard…</p>
}'use client'
// app/error.tsx
export default function Error({ reset }: { reset: () => void }) {
return <button onClick={reset}>Try again</button>
}export const metadata = {
title: 'My Blog',
description: 'Thoughts on building for the web',
}import Image from 'next/image'
<Image src="/hero.png" alt="Hero" width={800} height={400} priority />// .env.local
DATABASE_URL="postgresql://..."
NEXT_PUBLIC_SITE_NAME="DevPath"
// server code
const db = process.env.DATABASE_URL