Dev Helpers
← Back

Departure after selected time

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

Open this example in the interactive library

Source code

// app/trains/page.tsx

export default async function DepartureAfterSelectedTime({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const trains = [
    { id: "A1", to: "Union", min: 510, track: 2, delay: 4 },
    { id: "B4", to: "West", min: 560, track: 1, delay: 0 },
    { id: "A2", to: "Union", min: 600, track: 2, delay: 12 },
  ];
  const { after } = await searchParams;
  const t = Number(after ?? 540);
  return (
    <ol>
      {trains
        .filter((r) => r.min + r.delay >= t)
        .map((r) => (
          <li key={r.id}>
            {r.id} to {r.to}
          </li>
        ))}
    </ol>
  );
}