blob: 79f1ec2ac9e9f1d2e873460a6e06540ee08ac91f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import useSWR from "swr";
interface Stop {
stopId: number
name: string;
latitude?: number;
longitude?: number;
lines: string[];
}
export function Home() {
const { data, error, isLoading } = useSWR<Stop[]>('home', async () => {
const response = await fetch('/api/ListStops')
return response.json()
});
if (isLoading) return <h1>Loading...</h1>
if (error) return <h1>Error</h1>
return (
<>
<h1>Home</h1>
<ul>
{data?.map((stop: Stop) => (
<li key={stop.stopId}>
{stop.name} - {stop.lines?.join(', ')}
</li>
))}
</ul>
</>
)
}
|