completefrontend

Predict the outputMedium

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.tsx
export 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.tsx
import 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.tsx
export default function GreenTea() {
  return <h1>Green tea</h1>;
}
app/teas/mint/page.tsx
export 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:

  1. You run next build and next start, and open /teas/green in a browser.
  2. You click Add a cup.
  3. You click Add a cup again.
  4. You click the Mint tea link.
  5. 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…