Dev Helpers
← Back

Destination frequency summary

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 function DestinationFrequencySummary() {
  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 },
  ];
  return (
    <dl>
      {[...new Set(trains.map((t) => t.to))].map((to) => (
        <div key={to}>
          <dt>{to}</dt>
          <dd>{trains.filter((t) => t.to === to).length} departures</dd>
        </div>
      ))}
    </dl>
  );
}