throttle
Creates a throttled function that only invokes `fn` at most once per `limit` milliseconds. Useful for reducing the number of times a function is called during events that occur frequently, such as scrolling.> throttle(fn: (...args: any[]) => void, limit: number)
- fn: The function to throttle.
- limit: The minimum time interval (in milliseconds) between calls.
- Returns: A throttled version of the original function.
Example
import { throttle } from "@explita/daily-toolset";
function onScroll() {
console.log("Scrolled!");
}
const throttledScroll = throttle(onScroll, 200);
window.addEventListener("scroll", throttledScroll);