UNPKG

@d3vtool/hooks

Version:

Collection of custom React hooks to simplify tasks in your React projects.

21 lines (20 loc) 998 B
export type ms = number; export type DebounceAction<T extends any[]> = (...values: T) => void; /** * A custom React hook to debounce a given action, ensuring it is only called after a specified delay has passed * since the last invocation. Useful for optimizing performance during events like typing or resizing. * * @param delay - The amount of time in milliseconds to wait before invoking the action after the last event. * @param debounceAction - The action (callback function) to be executed after the debounce delay. * * @returns A function that, when invoked, triggers the debounce timer and eventually calls the `debounceAction` * after the specified delay. * * @example * const handleDebouncedSearch = useDebounce(300, () => { * // Perform a search or any action that should be debounced * }); * * <input onChange={handleDebouncedSearch} /> */ export declare function useDebounce<T extends any[]>(delay: ms, debounceAction: DebounceAction<T>): DebounceAction<T>;