useDebounce.ts 550 B

1234567891011121314151617181920212223242526
  1. import type {
  2. DebounceAndThrottleOptions,
  3. DebounceAndThrottleProcedureResult,
  4. DebounceAndThrottleProcedure,
  5. } from './types';
  6. import {
  7. // throttle,
  8. useThrottle,
  9. } from './useThrottle';
  10. /**
  11. * @description: Applicable in components
  12. */
  13. export function useDebounce<T extends unknown[]>(
  14. handle: DebounceAndThrottleProcedure<T>,
  15. wait: number,
  16. options: DebounceAndThrottleOptions = {}
  17. ): DebounceAndThrottleProcedureResult<T> {
  18. return useThrottle(
  19. handle,
  20. wait,
  21. Object.assign(options, {
  22. debounce: true,
  23. })
  24. );
  25. }