useThrottleFn
Throttle a function so it can only be called once every specified delay interval.
Installation
bash
npx kuro-ui add useThrottleFnbash
npx github:Bartek-Nowak/Kuro add useThrottleFnUsage
ts
import { useThrottleFn } from '@/composables/kuro/useThrottleFn'
const { throttled } = useThrottleFn(callback, 500)Parameters
| Name | Type | Description |
|---|---|---|
| fn | (...args: any[]) => any | Function to be throttled. |
| delay | number (optional, default = 300) | Minimum delay in milliseconds between function calls. |
Returns
| Name | Type | Description |
|---|---|---|
| throttled | (...args: Parameters<T>) => void | The throttled version of the provided function. |
Details
- The
fnwill only be invoked once perdelayinterval. - Calls during the delay period are ignored.
- Useful for performance-sensitive events like scroll, resize, or mousemove.