Dev Helpers
← Back

Rental return date

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

Open this example in the interactive library

Source code

// app/rental/page.tsx

export default async function RentalReturnDate({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const equipment = [
    { id: "press", day: 40, deposit: 100, qty: 2 },
    { id: "lamp", day: 12, deposit: 25, qty: 8 },
    { id: "stand", day: 8, deposit: 10, qty: 5 },
  ];
  const { start, days } = await searchParams;
  const day = typeof start === "string" ? Date.parse(start) : NaN;
  const span = Math.min(365, Math.max(1, Number(days) || 1));
  return (
    <p>
      {Number.isFinite(day)
        ? "Return by " + new Date(day + span * 86400000).toISOString().slice(0, 10)
        : "Choose a valid start date."}{" "}
      · {equipment.length} equipment types
    </p>
  );
}