shadcn-ahooks

useThrottleFn

A hook that deal with the throttled function.

Overview

A hook that deal with the throttled function.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useThrottleFn.json

A hook that deal with the throttled function.

Examples

Default usage

API

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

On this page