shadcn-ahooks

useDebounceFn

A hook that deal with the debounced function.

Overview

A hook that deal with the debounced function.

Documentation and Examples

Installation

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

A hook that deal with the debounced function.

Examples

Default usage

API

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.number1000
leadingSpecify invoking on the leading edge of the timeout.booleanfalse
trailingSpecify invoking on the trailing edge of the timeout.booleantrue
maxWaitThe maximum time func is allowed to be delayed before it’s invoked.number-

Result

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

On this page