Skip to content

Instantly share code, notes, and snippets.

@joekolade
Created March 3, 2023 11:21
Show Gist options
  • Select an option

  • Save joekolade/8873eb75012dc6bc9cd0e315ea30e230 to your computer and use it in GitHub Desktop.

Select an option

Save joekolade/8873eb75012dc6bc9cd0e315ea30e230 to your computer and use it in GitHub Desktop.
[JS Debounce] Simple debouncer function
/*
@param : fn => the function to convert
@param : time => the time delay for debounce
*/
function debounce(fn, delay) {
let timer = null
return (...args) => {
if (timer) clearTimeout(timer)
timer = setTimeout(() => fn(...args), delay)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment