A counter lives in a layout. What does it show after you follow a <Link>, and then a plain <a>?
The tea shop's teas layout has a cup counter, a Client Component, above each tea's page. Its menu links to Mint tea with <Link> and to Green tea with a plain <a>. You add two cups on the Green tea page, then follow both links. What does the page show after each step?
app/layout.tsxexport const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
app/teas/layout.tsximport Link from "next/link";
import CupCounter from "./cup-counter";
export default function TeasLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<>
<nav>
<a href="/teas/green">Green tea</a> <Link href="/teas/mint">Mint tea</Link>
</nav>
<CupCounter />
{children}
</>
);
}
app/teas/cup-counter.tsx"use client";
import { useState } from "react";
export default function CupCounter() {
const [cups, setCups] = useState(0);
return (
<p>
Cups: {cups} <button onClick={() => setCups(cups + 1)}>Add a cup</button>
</p>
);
}
app/teas/green/page.tsxexport default function GreenTea() {
return <h1>Green tea</h1>;
}
app/teas/mint/page.tsxexport default function MintTea() {
return <h1>Mint tea</h1>;
}
It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build and run with next start. What happens:
- You run
next buildandnext start, and open/teas/greenin a browser. - You click Add a cup.
- You click Add a cup again.
- You click the Mint tea link.
- You click the Green tea link.
The answer
Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.
Checking your sign-in…