Community Snippets

Debounce a function

by DevTools Cloud

TypeScript

A minimal debounce helper — click into it to see the full snippet page.

#demo#typescript#utility
function debounce<T extends (...args: unknown[]) => void>(fn: T, delayMs: number) {
  let timer: ReturnType<typeof setTimeout>;
  return (...args: Parameters<T>) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), delayMs);
  };
}

Comments (1)

Abba Sali Aboubakar Mamate8/15/2026

Merci

Sign in to leave a comment.