react-viewport-utils
Version:
Utility components for working with the viewport in react
20 lines (16 loc) • 361 B
JavaScript
// @flow strict-local
export default function debounce<TArgs: Array<mixed>>(
fn: (...args: TArgs) => mixed,
delay: number,
): (...args: TArgs) => void {
let timeout;
return function(...args: TArgs) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
timeout = null;
fn(...args);
}, delay);
};
}