Skip to content

useThrottleFn

Throttle a function so it can only be called once every specified delay interval.

Installation

bash
npx kuro-ui add useThrottleFn
bash
npx github:Bartek-Nowak/Kuro add useThrottleFn

Usage

ts
import { useThrottleFn } from '@/composables/kuro/useThrottleFn'

const { throttled } = useThrottleFn(callback, 500)

Parameters

NameTypeDescription
fn(...args: any[]) => anyFunction to be throttled.
delaynumber (optional, default = 300)Minimum delay in milliseconds between function calls.

Returns

NameTypeDescription
throttled(...args: Parameters<T>) => voidThe throttled version of the provided function.

Details

  • The fn will only be invoked once per delay interval.
  • Calls during the delay period are ignored.
  • Useful for performance-sensitive events like scroll, resize, or mousemove.