Dev Helpers
← Back

Multi-day equipment quote

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 MultiDayEquipmentQuote({
  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 { item, days } = await searchParams;
  const e = equipment.find((x) => x.id === item) ?? equipment[0];
  const d = Math.max(1, Math.trunc(Number(days) || 1));
  return (
    <p>
      {e.id} for {d} days: {d * e.day}
    </p>
  );
}