UNPKG

@zendesk/react-measure-timing-hooks

Version:

react hooks for measuring time to interactive and time to render of components

30 lines (29 loc) 1.33 kB
/** * Copyright Zendesk, Inc. * * Use of this source code is governed under the Apache License, Version 2.0 * found at http://www.apache.org/licenses/LICENSE-2.0. */ export declare const DebounceReason: unique symbol; export declare const TimeoutReason: unique symbol; export type FlushReason = typeof DebounceReason | typeof TimeoutReason | string; type FnToBeDebounced<Args extends readonly unknown[]> = (...args: [...args: Args, flushReason: FlushReason]) => boolean | undefined | void; export interface DebounceOptionsRef<Args extends readonly unknown[]> { fn: FnToBeDebounced<Args>; debounceMs: number; timeoutMs?: number; } export type DebouncedFn<Args extends readonly unknown[]> = ((...args: Args) => void) & { cancel: () => void; reset: () => Args | undefined; flush: (reason?: FlushReason) => boolean; getIsScheduled: () => boolean; }; /** * A simple debounce function that is easier to test against than the lodash one. * In addition it offers a way to check whether the last call was due to a timeout or not, * and a way to manually clear that timeout state. * Options may change even after the debounce was created by the means of a ref. */ export declare const debounce: <Args extends readonly unknown[]>(optionsRef: DebounceOptionsRef<Args>) => DebouncedFn<Args>; export {};