debounce
Commons
stable
Wraps a function so that it is only called after the specified delay has elapsed since the last invocation. Accepts a reactive delay (MaybeRef<number>) so the interval can be updated at runtime. The returned wrapper exposes .clear() and .immediate shortcuts.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- fnrequired(...args: any[]) => void
- The function to debounce.
- delayrequiredMaybeRef<number>
- Milliseconds to wait after the last call before invoking fn. Accepts a plain number or a Vue ref so the delay can be changed reactively.
API
Return value
The value returned by this util.
- A debounced wrapper. Call .clear() to cancel a pending invocation. Access .immediate to invoke fn synchronously without debouncing.
Usage
Examples
Ready-to-paste usage snippets.
Debounce a search handler