import { useEffect, useState } from "react"; import type { HealthStatus } from "@launchpad/shared"; export function useBackendHealth() { const [health, setHealth] = useState(null); const [error, setError] = useState(false); useEffect(() => { let cancelled = false; async function check() { try { const res = await fetch("/api/health"); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data: HealthStatus = await res.json(); if (!cancelled) { setHealth(data); setError(false); } } catch { if (!cancelled) setError(true); } } check(); const interval = setInterval(check, 10_000); return () => { cancelled = true; clearInterval(interval); }; }, []); return { health, error }; }