What Next.js adds
React builds the interface: components, props and state. A real website needs more around it:
- many pages, each with its own address;
- a server to load data and save changes;
- a way to make it all fast to load.
Next.js is a framework built on React that provides those. You still write React components, but where a file lives decides its address, and a component can run on the server, not just in the browser.
This course uses Next.js's App Router: the app/ folder. It assumes React
components, props, state, events and controlled forms. If those are unfamiliar,
start with React beginner.
The labs simulate a Next.js server inside your browser. They are not a hosted Next.js deployment, and every project file is visible to the reader. Use only practice data in them. Day 7 runs the downloaded project with real Next.js.
Your first project
npm install and npm run dev. There are three files:
| File | What it is |
|---|---|
app/page.jsx | The page at /, the home page |
app/layout.jsx | The root layout: it wraps every page |
app/globals.css | Styles for the whole site, imported by the layout |
The preview has an address bar, like a small browser. It says /, the page
you're on. It navigates inside this lab, not the learning website.
When an exercise asks for a new file, enter its full relative path in File path under the lab, press Add file, then write its code in the editor. To remove a file, enter its path and press Remove file. Restore starter files brings back the original project and replaces your edits; download work you want to keep first. Downloads include your added files.
The page
export default function HomePage() {
console.log("Rendering the home page");
return (
<main>
<h1>Hello, Next.js</h1>
<p>This page is the file app/page.jsx.</p>
</main>
);
}A page is an ordinary React component, the file's default export. Next.js finds it by its file name: you never import it or render it yourself.
The layout
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<header>Study Hub</header>
{children}
</body>
</html>
);
}The layout gets the current page as children. Whatever it renders around
children, here a header, appears on every page. The root layout is the only
component that renders <html> and <body>; nothing else in the project
should.
Predict
The page calls console.log. Look at the console under the preview: what's
different about that line from the logs in the React courses?
Check your prediction
It starts with [server]. Pages run on the server by default, not in the browser. In this lab, a worker inside the preview plays the server. When you run Next.js on your own computer, the line appears in the terminal where the server runs. Development tooling can also forward server logs to browser devtools; seeing a log there doesn't prove its code ran in the browser. Day 2 explains the rendering boundary.
Make it yours
Change the header to your own site's name, and add a second paragraph to the page that says what you want to learn.
npm install and npm run dev. Hint 1: the idea
Shared content belongs in a layout; content for one URL belongs in its page. Decide which file owns each change.
Hint 2: a first step
The header is in app/layout.jsx; the paragraph goes inside <main> in
app/page.jsx. Press Run after editing.
Show one solution
In app/layout.jsx:
<header>Ada's Study Hub</header>In app/page.jsx, under the first paragraph:
<p>I want to learn how pages load data.</p>Completion is saved in this browser only. It does not measure mastery.