Open this example in the interactive library
Source code
// app/billing/page.tsx
import Link from "next/link";
export default async function InvoiceMonthLinks({
searchParams,
}: {
searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
const invoices = [
{ id: "A", cents: 3200, paid: true, due: "2028-01-10" },
{ id: "B", cents: 7900, paid: false, due: "2028-02-15" },
{ id: "C", cents: 4600, paid: false, due: "2028-03-20" },
];
const months = [...new Set(invoices.map((i) => i.due.slice(0, 7)))];
const { month } = await searchParams;
return (
<main>
<nav>
{months.map((m) => (
<Link key={m} href={{ query: { month: m } }}>
{m}{" "}
</Link>
))}
</nav>
{invoices
.filter((i) => i.due.startsWith(String(month ?? "")))
.map((i) => (
<p key={i.id}>{i.id}</p>
))}
</main>
);
}
