shadimage
Hookagain
hookuse-debounced-callbacksource: ok · refreshed

Use Debounced Callback

npx shadcn add "https://hookagain.vercel.app/r/use-debounced-callback.json"
free

No selection tags yet — empty means no evidence, not lack of support.

Files1 · source cached 10/2/2026, 1:58:17 AM

hooks/use-debounced-callback.ts
import * as React from "react";

export function useDebouncedCallback<T extends (...args: any[]) => any>(
	callback: T,
	delay = 500,
) {
	const timeoutRef = React.useRef<NodeJS.Timeout>();

	return React.useCallback(
		(...args: Parameters<T>) => {
			if (timeoutRef.current) {
				clearTimeout(timeoutRef.current);
			}

			timeoutRef.current = setTimeout(() => {
				callback(...args);
			}, delay);
		},
		[callback, delay],
	);
}

More from Hookagain

Browse all components in this library →