export interface DebounceAndThrottleOptions { // 立即执行 immediate?: boolean; // 是否为debounce debounce?: boolean; // 只执行一次 once?: boolean; } export type CancelFn = () => void; export type DebounceAndThrottleProcedure = (...args: T) => unknown; export type DebounceAndThrottleProcedureResult = [ DebounceAndThrottleProcedure, CancelFn ]; import { // throttle, useThrottle, } from './useThrottle'; /** * @description: Applicable in components */ export function useDebounce( handle: DebounceAndThrottleProcedure, wait: number, options: DebounceAndThrottleOptions = {} ): DebounceAndThrottleProcedureResult { return useThrottle( handle, wait, Object.assign(options, { debounce: true, }) ); }