fix: make useLiveData a context that is pausable
This commit is contained in:
parent
98d02bb595
commit
c066b3064d
5 changed files with 89 additions and 61 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue