Dev Helpers
← Back

Affordable gear filter

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 AffordableGearFilter({
  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 { budget } = await searchParams;
  const max = Number(budget ?? 20);
  return (
    <ul>
      {equipment
        .filter((e) => e.day <= max)
        .map((e) => (
          <li key={e.id}>
            {e.id}: {e.day}/day
          </li>
        ))}
    </ul>
  );
}