mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 08:31:59 +08:00

* logs is updated * fix: log live tail is updated * fix: live tail is fixed * chore: build is fixed * chore: useEffect is removed * chore: getLogsAggregate callback is added in the useEffect
36 lines
559 B
TypeScript
36 lines
559 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
function useInterval(
|
|
callback: () => void,
|
|
delay: number,
|
|
enabled = true,
|
|
): void {
|
|
const savedCallback = useRef<() => void>();
|
|
|
|
useEffect(() => {
|
|
savedCallback.current = callback;
|
|
});
|
|
|
|
useEffect(() => {
|
|
function tick(): void {
|
|
if (savedCallback.current) {
|
|
savedCallback.current();
|
|
}
|
|
}
|
|
|
|
let id: NodeJS.Timer;
|
|
|
|
if (enabled) {
|
|
id = setInterval(tick, delay);
|
|
}
|
|
|
|
return (): void => {
|
|
if (id) {
|
|
clearInterval(id);
|
|
}
|
|
};
|
|
}, [delay, enabled]);
|
|
}
|
|
|
|
export default useInterval;
|