/** * useRateLimiting Hook * * Unified hook for throttling and debouncing function calls. * Replaces separate useThrottle and useDebounce hooks with a single, * more flexible implementation. * * @since v1.35.0 */ /** * Rate limiting mode */ export type RateLimitMode = 'throttle' | 'debounce'; /** * Options for useRateLimiting */ export interface UseRateLimitingOptions { /** Rate limiting mode */ mode: RateLimitMode; /** Wait time in milliseconds */ wait: number; /** Execute on leading edge (default: true for throttle, false for debounce) */ leading?: boolean; /** Execute on trailing edge (default: false for throttle, true for debounce) */ trailing?: boolean; /** Maximum wait time before forcing execution (debounce only) */ maxWait?: number; } /** * Return type for useRateLimiting */ export interface UseRateLimitingReturn unknown> { /** The rate-limited function */ fn: (...args: Parameters) => ReturnType | undefined; /** Whether there's a pending call */ isPending: boolean; /** Cancel any pending call */ cancel: () => void; /** Immediately execute any pending call */ flush: () => void; } /** * Unified rate limiting hook for throttle and debounce * * @param callback - Function to rate limit * @param options - Rate limiting options * @returns Rate-limited function and control methods * * @example * ```typescript * // Throttle: execute immediately, then at most once per 500ms * const { fn: throttledScan } = useRateLimiting(scanServers, { * mode: 'throttle', * wait: 500, * }); * * // Debounce: wait 300ms after last call before executing * const { fn: debouncedSearch, isPending } = useRateLimiting(search, { * mode: 'debounce', * wait: 300, * }); * * // Debounce with max wait: execute after 1000ms even if still typing * const { fn: debouncedSave } = useRateLimiting(save, { * mode: 'debounce', * wait: 300, * maxWait: 1000, * }); * ``` */ export declare function useRateLimiting unknown>(callback: T, options: UseRateLimitingOptions): UseRateLimitingReturn; /** * Convenience hook for throttling */ export declare function useThrottle unknown>(callback: T, wait: number, options?: { leading?: boolean; trailing?: boolean; }): UseRateLimitingReturn; /** * Convenience hook for debouncing */ export declare function useDebounce unknown>(callback: T, wait: number, options?: { leading?: boolean; trailing?: boolean; maxWait?: number; }): UseRateLimitingReturn; /** * Hook for debouncing a value */ export declare function useDebouncedValue(value: T, wait: number): T; /** * Simple throttle that just returns the function (backward compatible) */ export declare function useThrottleFn unknown>(callback: T, wait: number, options?: { leading?: boolean; trailing?: boolean; }): (...args: Parameters) => ReturnType | undefined; /** * Simple debounce that just returns the function (backward compatible) */ export declare function useDebounceFn unknown>(callback: T, wait: number, options?: { leading?: boolean; trailing?: boolean; maxWait?: number; }): (...args: Parameters) => ReturnType | undefined; //# sourceMappingURL=useRateLimiting.d.ts.map