@andranik-arakelyan/js-utilities
Version:
Javascript utilities
22 lines (21 loc) • 834 B
TypeScript
/**
* Creates a throttled function that only invokes the provided function at most once
* per every specified wait milliseconds, regardless of how many times it's called.
*
* @param func - The function to throttle
* @param wait - The number of milliseconds to throttle invocations to
* @returns A throttled function that limits invocation to once per wait period
*
* @example
* // Create a throttled version of a function
* const handleScroll = throttle(() => {
* // Process the scroll event
* console.log('Processing scroll event');
* }, 300);
*
* // Call the throttled function
* window.addEventListener('scroll', handleScroll);
*/
export declare function throttle<T extends (...args: any[]) => any>(func: T, wait: number): ((...args: Parameters<T>) => ReturnType<T> | undefined) & {
cancel: () => void;
};