import { useCallback } from 'react'; import { fetchJson } from './fetchJson'; import { MatchCard, type Match } from './MatchCard'; import { useBackoffUntilSuccess } from './useBackoffUntilSuccess'; export type ApiResponse = { count: number; matches: Match[]; fetchedAt: string; }; export default function App() { const fetchLive = useCallback(() => fetchJson('http://localhost:8787/api/live', { headers: { 'cache-control': 'no-cache' } }), []); const fetchToday = useCallback(() => fetchJson('http://localhost:8787/api/matches', { headers: { 'cache-control': 'no-cache' } }), []); const live = useBackoffUntilSuccess(fetchLive); const today = useBackoffUntilSuccess(fetchToday); return (

UEFA Champions League — Live Scores

Live right now

{live.loading &&

Loading…

} {live.error &&

{live.error}{typeof live.retryInSec === 'number' ? ` (${live.retryInSec}s)` : ''}

} {!live.loading && !live.error && live.data?.matches?.length === 0 &&

No live matches.

}
{live.data?.matches?.map(m => )}

Today

{today.loading &&

Loading…

} {today.error &&

{today.error}{typeof today.retryInSec === 'number' ? ` (${today.retryInSec}s)` : ''}

}
{today.data?.matches?.map(m => )}
); }