UNPKG

rooks

Version:

Collection of awesome react hooks

26 lines (25 loc) 969 B
import { AnyFunction } from "../types/utils"; export interface DebounceSettings { leading?: boolean; maxWait?: number; trailing?: boolean; } type DebouncedFunction<T extends (...args: any[]) => any> = T & { cancel(): void; flush(): ReturnType<T> | undefined; }; /** * Debounce hook * Debounces a function * * @param callback The callback to debounce * @param wait The duration to debounce * @param options The options object. * @param options.leading Specify invoking on the leading edge of the timeout. * @param options.maxWait The maximum time func is allowed to be delayed before it's invoked. * @param options.trailing Specify invoking on the trailing edge of the timeout. * @returns Returns the new debounced function. * @see https://rooks.vercel.app/docs/hooks/useDebounce */ declare function useDebounce<T extends AnyFunction>(callback: T, wait?: number, options?: DebounceSettings): DebouncedFunction<T>; export { useDebounce };