Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
646 B ยท 29 lines
TypeScript
123456789101112131415161718192021222324252627282930import { useCallback, useEffect, useRef } from "react";
export function useDebounceCallback<Args extends unknown[]>( callback: (...args: Args) => void, delay = 500,) { const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const debounced = useCallback( (...args: Args) => { if (timerRef.current) { clearTimeout(timerRef.current); }
timerRef.current = setTimeout(() => { callback(...args); }, delay); }, [callback, delay], );
useEffect(() => { return () => { if (timerRef.current) clearTimeout(timerRef.current); }; }, []);
return debounced;}