Throttle a function call with run/cancel/flush/pending controls.
function useThrottleFn<T extends (...args: unknown[]) => void>(
fn: T,
wait: number,
options?: {
leading?: boolean;
trailing?: boolean;
}
): {
run: (...args: Parameters<T>) => void;
cancel: () => void;
flush: () => void;
pending: () => boolean;
};const throttled = useThrottleFn(() => {
updateScroll();
}, 16);
window.addEventListener('scroll', throttled.run);