useThrottle
A hook to throttle a value
Loading...
Installation
npx shadcn@latest add @shadcnhooks/use-throttleAPI
interface ThrottleOptions {
/**
* An optional AbortSignal to cancel the throttled function.
*/
signal?: AbortSignal
/**
* An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
* If `edges` includes "leading", the function will be invoked at the start of the delay period.
* If `edges` includes "trailing", the function will be invoked at the end of the delay period.
* If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
* @default ["leading", "trailing"]
*/
edges?: Array<'leading' | 'trailing'>
}
/**
* A hook to throttle a value
* @param value - The value to throttle
* @param throttleMs - The throttle time in milliseconds default to 1000
* @param options - The options for the throttle value
* @returns The throttled value
*/
function useThrottle<T>(
value: T,
throttleMs?: number,
options?: ThrottleOptions,
): TCredits
Last updated on