Download bin/cli/tui-components/HeaderSwr.jsx from rais133/omniroute: direct link, hf CLI and curl.
- Browser
- Download file 634 Bytes
-
https://huggingface.co/spaces/rais133/omniroute/resolve/main/bin/cli/tui-components/HeaderSwr.jsx
- Command line
-
hf download hf://spaces/rais133/omniroute/bin/cli/tui-components/HeaderSwr.jsx
-
curl -L -o HeaderSwr.jsx https://huggingface.co/spaces/rais133/omniroute/resolve/main/bin/cli/tui-components/HeaderSwr.jsx
634 Bytes
| import React, { useEffect, useState } from "react"; | |
| import { Text } from "ink"; | |
| export function HeaderSwr({ fetcher, interval = 5000, render, initial = null }) { | |
| const [data, setData] = useState(initial); | |
| useEffect(() => { | |
| let cancelled = false; | |
| async function tick() { | |
| try { | |
| const next = await fetcher(); | |
| if (!cancelled) setData(next); | |
| } catch {} | |
| } | |
| tick(); | |
| const id = setInterval(tick, interval); | |
| return () => { | |
| cancelled = true; | |
| clearInterval(id); | |
| }; | |
| }, [fetcher, interval]); | |
| if (!data) return <Text dimColor>Loading…</Text>; | |
| return render(data); | |
| } | |