Hello, Next.js! --- Your First App
⏱ 10 min read read
What is Next.js?
Next.js is a React framework built by Vercel. It adds server-side
rendering (SSR), static site generation (SSG), file-based routing, API
routes, image optimisation, and much more on top of React --- all with
zero config.
React handles the UI. Next.js handles routing, rendering, and the
server.
Next.js 13+ introduced the App Router --- the modern, recommended
approach.
Files in app/ automatically become routes. No react-router needed.
Run locally with: npx create-next-app@latest my-app
Project Structure (App Router):
my-app/
├── app/
│ ├── layout.tsx ← Root layout (wraps every page)
│ ├── page.tsx ← Home route /
│ ├── about/
│ │ └── page.tsx ← About route /about
│ └── globals.css
├── public/ ← Static files (images, fonts)
├── next.config.js
└── package.json
Server Components vs Client Components:
By default ALL components in the App Router are Server Components ---
they render on the server and send HTML. No JavaScript bundle shipped
for them.
Add 'use client' at the top of a file to make it a Client Component
--- it can use useState, useEffect, event handlers, and browser APIs.
IMPORTANT: Server Components CANNOT use useState, useEffect, or
browser APIs.
Client Components CAN, but they add JavaScript to the browser bundle.
Rule of thumb: keep as much as possible as Server Components.
Only add 'use client' when you need interactivity or browser APIs.
Running the Dev Server:
npx create-next-app@latest my-app # create project
cd my-app
npm run dev # start dev server at localhost:3000
npm run build # production build
npm start # run production build
Next.js is a React framework built by Vercel. It adds server-side
rendering (SSR), static site generation (SSG), file-based routing, API
routes, image optimisation, and much more on top of React --- all with
zero config.
React handles the UI. Next.js handles routing, rendering, and the
server.
Next.js 13+ introduced the App Router --- the modern, recommended
approach.
Files in app/ automatically become routes. No react-router needed.
Run locally with: npx create-next-app@latest my-app
Project Structure (App Router):
my-app/
├── app/
│ ├── layout.tsx ← Root layout (wraps every page)
│ ├── page.tsx ← Home route /
│ ├── about/
│ │ └── page.tsx ← About route /about
│ └── globals.css
├── public/ ← Static files (images, fonts)
├── next.config.js
└── package.json
Server Components vs Client Components:
By default ALL components in the App Router are Server Components ---
they render on the server and send HTML. No JavaScript bundle shipped
for them.
Add 'use client' at the top of a file to make it a Client Component
--- it can use useState, useEffect, event handlers, and browser APIs.
IMPORTANT: Server Components CANNOT use useState, useEffect, or
browser APIs.
Client Components CAN, but they add JavaScript to the browser bundle.
Rule of thumb: keep as much as possible as Server Components.
Only add 'use client' when you need interactivity or browser APIs.
Running the Dev Server:
npx create-next-app@latest my-app # create project
cd my-app
npm run dev # start dev server at localhost:3000
npm run build # production build
npm start # run production build
Log in to track your progress and earn badges as you complete lessons.
Log In to Track Progress