const debounce = (func, timeout = 2500) => {
if (typeof func !== "function") {
console.error(`func must be a valid function, ${typeof func} provided`)
return
}
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(() => {
func.apply(this, args)
}, timeout)
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter