Skip to content

useDebounceFn ​

A hook that deal with the debounced function.

Code demonstration ​

API ​

typescript
const {
  run,
  cancel,
  flush
} = useDebounceFn(
  fn: (...args: any[]) => any,
  options?: Options
);

Params ​

PropertyDescriptionTypeDefault
fnThe function to debounce.(...args: any[]) => any-
optionsConfig for the debounce behaviors.Options-

Options ​

PropertyDescriptionTypeDefault
waitThe number of milliseconds to delay.number|Ref<number>1000
leadingSpecify invoking on the leading edge of the timeout.boolean|Ref<boolean>false
trailingSpecify invoking on the trailing edge of the timeout.boolean|Ref<boolean>true
maxWaitThe maximum time func is allowed to be delayed before it’s invoked.number|Ref<number>-

Result ​

PropertyDescriptionType
runInvode and pass parameters to fn.(...args: any[]) => any
cancelCancel the invocation of currently debounced function.() => void
flushImmediately invoke currently debounced function.() => void

Remark

  • options.wait support dynamic changes.
  • options.leading support dynamic changes.
  • options.trailing support dynamic changes.
  • options.maxWait support dynamic changes.

Source ​

Source · Document · Demo

Released under the MIT License.