Skip to content
On this page

useThrottleFn

A hook that deal with the throttled function.

Code demonstration

API

const {
  run,
  cancel,
  flush
} = useThrottleFn(
  fn: (...args: any[]) => any,
  options?: Options
);
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

SourceDocsDemo