DEV/DEV4.1/tp4/ex1/js/helpers.js
2024-03-01 15:39:57 +01:00

13 lines
341 B
JavaScript

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds.
function debounce(fn, wait) {
let timeout
return (...args) => {
clearTimeout(timeout)
timeout = setTimeout(() => fn(...args), wait)
}
}
export default debounce