debounce
Creates a debounced function that delays invoking `fn` until after `delay` milliseconds have passed since the last time it was called. This is useful for limiting the rate of function calls in response to events like resizing or typing.> debounce<T extends (...args: any[]) => void>(fn: T, delay: number):
((...args: Parameters<T>) => void)
- fn: The function to debounce.
- delay: The number of milliseconds to delay.
- Returns: A debounced version of the original function.
Example
import { debounce } from "@explita/daily-toolset";
function onResize() {
console.log("Window resized");
}
const debouncedResize = debounce(onResize, 300);
window.addEventListener("resize", debouncedResize);