MCPcopy Create free account
hub / github.com/coder/coder / useTime

Function useTime

site/src/hooks/useTime.ts:21–43  ·  view source on GitHub ↗
(func: () => T, options: UseTimeOptions = {})

Source from the content-addressed store, hash-verified

19 * approaches.
20 */
21export function useTime<T>(func: () => T, options: UseTimeOptions = {}): T {
22 const [computedValue, setComputedValue] = useState(() => func());
23 const { disabled = false, interval = 1000 } = options;
24
25 const thunk = useEffectEvent(func);
26
27 useEffect(() => {
28 if (disabled) {
29 return;
30 }
31
32 const handle = setInterval(() => {
33 const next = thunk();
34 setComputedValue(() => next);
35 }, interval);
36
37 return () => {
38 clearInterval(handle);
39 };
40 }, [disabled, interval]);
41
42 return computedValue;
43}

Callers 1

AutostopDisplayFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected