- Docs
Debounce
What @samline/debounce does, when to use debounce, throttle or rafThrottle, and where to start.
@samline/debounce controls how often a function runs. It ships three tools with the same returned controls:
| Tool | Runs | Use it for |
|---|---|---|
debounce | Once the calls stop for wait ms | Search, validation, resize end |
throttle | At most once every wait ms, plus the last call of a burst | Autosave, analytics, progress |
rafThrottle | At most once per animation frame | Scroll, pointer and layout reads |
Every returned function forwards this and its arguments, returns the last result and has cancel(), flush() and pending().
Choose your next step
Installation
Package managers, the CDN and the first debounced handler.
ExamplesLive previews with the complete, copyable source of each one.
API referenceEvery function and its return value.
ConfigurationDefaults and accepted values of leading, trailing and maxWait.
React, Vue and Svelte adapters.