mirror of
https://github.com/tale/headplane.git
synced 2026-08-18 17:06:17 +00:00
fix: make useLiveData a context that is pausable
This commit is contained in:
+2
-10
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef } from 'react';
|
||||
import { useFetcher } from 'react-router';
|
||||
import { HostInfo } from '~/types';
|
||||
|
||||
export default function useAgent(nodeIds: string[], interval = 3000) {
|
||||
export default function useAgent(nodeIds: string[]) {
|
||||
const fetcher = useFetcher<Record<string, HostInfo>>();
|
||||
const qp = useMemo(
|
||||
() => new URLSearchParams({ node_ids: nodeIds.join(',') }),
|
||||
@@ -15,15 +15,7 @@ export default function useAgent(nodeIds: string[], interval = 3000) {
|
||||
fetcher.load(`/api/agent?${qp.toString()}`);
|
||||
idRef.current = nodeIds;
|
||||
}
|
||||
|
||||
const intervalID = setInterval(() => {
|
||||
fetcher.load(`/api/agent?${qp.toString()}`);
|
||||
}, interval);
|
||||
|
||||
return () => {
|
||||
clearInterval(intervalID);
|
||||
};
|
||||
}, [interval, qp]);
|
||||
}, [qp.toString()]);
|
||||
|
||||
return {
|
||||
data: fetcher.data,
|
||||
|
||||
Reference in New Issue
Block a user