module-06-upgrade
The Next.js Upgrade
Module 6 — same marketplace, organized the right way
2nd Year · BSIT
Student Marketplace
Build · Upgrade, not restart
Callback
Remember the three walls
WALL 01
Data disappears
Listings live in browser memory. Refresh — gone. We fix this in Module 7, not today.
WALL 02
Copy-paste HTML
Every page retypes the nav. Today: write it once in layout.tsx.
WALL 03
No structure
Cards, pages, and data pile into loose files. Today: components + routes.
Next.js solves the walls you already felt. That is why we are using it.
The Frame
Same app. Better home.
Vanilla (Modules 2–4)
Looks right on screen. Under the hood: duplicated nav, a second HTML file, data that dies on refresh.
Next.js (today)
Same design. Same cards. Nav lives in one file. A new page is a new folder. Data is still fake — but centralized.
Nothing you built is thrown away. We are moving it into a better home.
Today's Build
What you will have by the end
- 1A running Next.js app at
localhost:3000
- 2Navbar once in
app/layout.tsx — every page gets it
- 3
ListingCard component + a listings array on the home page
- 4Click a card →
/listings/1 shows that listing
Scope
What we are not doing today
SKIP
React theory
No virtual DOM lecture. No “Next.js is a React framework” as the opening line.
SKIP
TypeScript course
Files end in .tsx. We are not learning types as a subject — only tiny labels when the editor complains.
SKIP
Database
Fake data stays fake. Prisma and API routes wait for Module 7.
Setup
Create the project
npx create-next-app@latest marketplace
cd marketplace
npm run dev
- If it asks recommended Next.js defaults → choose Yes
- That means TypeScript, Tailwind, App Router. Files will be
.tsx — that is correct
- Browser:
http://localhost:3000 — the default Next.js page means it worked
Do not panic
.tsx is not a new language
What you expected
page.js · layout.js · “TypeScript: No”
What Next.js creates now
page.tsx · layout.tsx · recommended defaults
- T = TypeScript labels. SX = the same tags you already know
- You still write HTML-looking code inside a function. The extra letters are just the file name
- Do not rename
.tsx to .js. Edit the files that are already there
Folders
Where things live
marketplace/
├── app/
│ ├── page.tsx
│ ├── layout.tsx
│ └── globals.css
├── components/
├── tsconfig.json
└── package.json
If your folders look different
Some installs put pages under src/
Recommended default
app/page.tsx
app/layout.tsx
If you chose src/
src/app/page.tsx
src/app/layout.tsx
Same files. Same job. Create components/ next to app/ — not inside it.
layout.tsx
One navbar. Every page.
// Keep the imports Next.js already added. Only add the nav.
<body>
<nav style={{backgroundColor: '#1d4ed8', padding: '16px 32px'}}>
<h1 style={{color: 'white'}}>Student Marketplace</h1>
</nav>
{children}
</body>
Change the nav here once. Home and detail both update. No copy-paste.
Component
ListingCard — the Module 2 card, once
// components/ListingCard.tsx
type CardProps = { title: string; price: number; description: string };
export default function ListingCard({ title, price, description }: CardProps) {
return (
<div style={{ backgroundColor: 'white', borderRadius: '12px', padding: '16px' }}>
<h3>{title}</h3>
<p>₱{price}</p>
<p>{description}</p>
</div>
);
}
- Props are the data passed in.
CardProps is a tiny label so the red squiggle goes away
- Change the card in this file — every listing on the home page updates
Home page
One array. Cards generate themselves.
// app/page.tsx — replace the welcome page
import ListingCard from '../components/ListingCard';
const listings = [
{ id: 1, title: 'Second-Hand Laptop', price: 8500, description: 'Core i5. Charger included.' },
{ id: 2, title: 'Calculus Textbook', price: 250, description: 'Lightly used.' },
{ id: 3, title: 'HDMI Cable', price: 150, description: '1.5 meters.' },
];
export default function Home() {
return (
<main>
{listings.map((item) => (
<ListingCard key={item.id} title={item.title} price={item.price} description={item.description} />
))}
</main>
);
}
Routing
A new page is a new file
app/
├── page.tsx
├── layout.tsx
└── listings/
└── [id]/
└── page.tsx
[id] is a dynamic segment. One file handles every listing URL.
Detail page
Read the id, find the listing
export default async function ListingDetail({
params,
}: { params: Promise<{ id: string }> }) {
const { id } = await params;
const listing = listings.find((item) => item.id === parseInt(id));
if (!listing) return <p>Listing not found.</p>;
return (
<main>
<h1>{listing.title}</h1>
<p>₱{listing.price}</p>
<p>{listing.description}</p>
</main>
);
}
- Copy the same
listings array into this file for now — Module 7 gives it one real home
Navigation
Click the card, keep the navbar
import Link from 'next/link';
{listings.map((item) => (
<Link key={item.id} href={"/listings/" + item.id}>
<ListingCard title={item.title} price={item.price} description={item.description} />
</Link>
))}
Old way: listing-detail.html + copy-pasted nav. New way: one file, one Link.
Compare
Vanilla files vs Next.js files
Old way
index.html
listing-detail.html
style.css
app.js
Nav typed twice
Cards typed by hand
Data dies on refresh
New way
app/layout.tsx
app/page.tsx
app/listings/[id]/page.tsx
components/ListingCard.tsx
Nav once
Cards from .map()
Data still fake — Module 7
Stuck?
Three errors you will see
NO PAGE.JS
Open page.tsx and layout.tsx. Those are the real files. Do not create a second page.js.
RED SQUIGGLE ON TITLE / PRICE
Add the small CardProps type on ListingCard.tsx. It is a label, not a new topic.
PARAMS.ID IS WRONG
Use const { id } = await params on the detail page. Current Next.js waits for the URL first.
Student Activity
Rebuild the marketplace in Next.js
MUST HAVE
components/ListingCard.tsx · navbar in app/layout.tsx · home maps an array · detail at app/listings/[id]/page.tsx
PROOF
Click a card on home. The detail page shows the correct title and price. Navbar is on both pages.
SUBMIT
GitHub repo URL + screenshots of home and detail. Follow the step page on the study hub.
What's Next
The hard part is behind you
- ✓Components — the card is written once
- ✓Layout — the navbar is written once
- ✓Routing — a file becomes a page
- →Module 7 replaces the fake array with PostgreSQL
- →Refresh will finally keep the listings
Same marketplace. Better organized. Questions?