()
| 30 | * a consumer mounts. |
| 31 | */ |
| 32 | export function useIssues(): UseIssues { |
| 33 | const [data, setData] = useState<IssueSnapshot | null>(cached) |
| 34 | const [error, setError] = useState<string | null>(null) |
| 35 | const mounted = useRef(true) |
| 36 | |
| 37 | useEffect(() => { |
| 38 | mounted.current = true |
| 39 | const load = async () => { |
| 40 | try { |
| 41 | const next = await api.issues.get() |
| 42 | cached = next |
| 43 | if (mounted.current) { |
| 44 | setData(next) |
| 45 | setError(null) |
| 46 | } |
| 47 | } catch (e) { |
| 48 | if (mounted.current) setError(e instanceof Error ? e.message : String(e)) |
| 49 | } |
| 50 | } |
| 51 | void load() |
| 52 | const id = setInterval(() => void load(), POLL_MS) |
| 53 | return () => { |
| 54 | mounted.current = false |
| 55 | clearInterval(id) |
| 56 | } |
| 57 | }, []) |
| 58 | |
| 59 | return { data, error, loading: data === null && error === null } |
| 60 | } |
no test coverage detected