throttle

Create a throttled function that runs at most once per interval, limiting how often expensive handlers fire during rapid events.

Usage

throttle wraps a function so that it executes at most once within the specified time interval.

import { throttle } from '@movk/core'

const throttledScroll = throttle((event: Event) => {
  console.log('Scroll event handled')
}, 100)

// Listen to scroll events, executing at most once every 100ms
window.addEventListener('scroll', throttledScroll)

API

throttle<T>(func, limit)

Create a throttled function that runs at most once per interval.

Parameters

func
T extends (...args: any[]) => any required
The function to throttle.
limit
number required
The throttle interval in milliseconds.

Returns

returns
(...args: Parameters<T>) => void
The throttled function.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License