Skip to content

useThrottleFn ​

A hook that deal with the throttled function.

Code demonstration ​

API ​

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

Params ​

PropertyDescriptionTypeDefault
fnThe function to throttle.(...args: any[]) => any-
optionsConfig for the throttle behaviorsOptions-

Options ​

PropertyDescriptionTypeDefault
waitThe number of milliseconds to delay.number1000
leadingSpecify invoking on the leading edge of the timeout.booleantrue
trailingSpecify invoking on the trailing edge of the timeout.booleantrue

Result ​

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

Source ​

Source · Document · Demo

Released under the MIT License.