Dev Helpers
← Back

Next collection date

Place this file at app/billing/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/billing/page.tsx

export default function NextCollectionDate() {
  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 next = invoices
    .filter((i) => !i.paid)
    .sort((a, b) => a.due.localeCompare(b.due))[0];
  return next ? (
    <time dateTime={next.due}>
      {next.id} due {next.due}
    </time>
  ) : (
    <p>All paid</p>
  );
}