Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useDesktopLocalBootstraps.ts

22 lines816 Bytes

1import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts";
2import { useEffect, useState } from "react";
3​
4import { readDesktopSecondaryBootstraps } from "./desktopLocal";
5​
6const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000;
7​
8/** The bridge has no change event. Poll, retaining the snapshot on failure and clearing on empty reads. */
9export function useDesktopLocalBootstraps(): ReadonlyArray<DesktopEnvironmentBootstrap> {
10 const [bootstraps, setBootstraps] = useState<ReadonlyArray<DesktopEnvironmentBootstrap>>(
11 readDesktopSecondaryBootstraps,
12 );
13​
14 useEffect(() => {
15 const read = () => setBootstraps(readDesktopSecondaryBootstraps());
16 read();
17 const interval = setInterval(read, DESKTOP_LOCAL_BOOTSTRAP_POLL_MS);
18 return () => clearInterval(interval);
19 }, []);
20​
21 return bootstraps;