Fewer calls. Same result.

Debounce
Call less, do more.

Debounce input, throttle work and run layout code once per frame with one small, dependency-free package.
Install it, try the live counter, then read the full reference.

npm install @samline/debounce

764 B gzipZero dependenciesMIT licensed

Debounce previewLive preview
Every event
0
debounce 300 ms
0
throttle 300 ms
0
rafThrottle
0

ONE SMALL SCRIPT. RIGHT AT HOME IN YOUR STACK.

JavaScript TypeScript React Vue Svelte Shopify WordPress
01 / More than a timer

Control every call.
Not just delay it.

Three tools, one API

debounce waits for quiet, throttle keeps a steady rate and rafThrottle runs once per animation frame.

Cancel, flush and pending

Drop a pending call when a dialog closes, run it now on submit, or check whether one is scheduled.

Predictable edges

leading, trailing and maxWait follow the well-known lodash semantics, with this and the last result forwarded.

Safe everywhere

Invalid waits become 0 and rafThrottle falls back to a timer without requestAnimationFrame, so SSR never throws.

Idiomatic adapters

React hooks, Vue composables and a Svelte store keep the latest callback and cancel on unmount.

Tiny and measured

Every entry point has a gzip budget checked in CI. The core is under 1 KB.

02 / Fit it into your stack

One package. Every runtime.

Import only what you need: the root entry tree-shakes, adapters are subpaths.

Package

@samline/debounce

debounce, throttle and rafThrottle as ESM or CommonJS.

React

@samline/debounce/react

useDebouncedCallback, useThrottledCallback and useDebouncedValue.

Vue

@samline/debounce/vue

useDebouncedCallback, useThrottledCallback and useDebouncedRef.

HTML / CDN

window.Debounce

A classic script for pages without a build step.

Svelte

@samline/debounce/svelte

createDebouncedStore with flush and cancel.

Types

DebouncedFunction

Typed options and returned functions, no CSS required.

03 / Install and debounce

One install. One quieter input.

Debounce a search field so the request runs once the user stops typing.

Read the installation guide
1

Install

npm

Terminal
npm install @samline/debounce

pnpm

Terminal
pnpm add @samline/debounce

yarn

Terminal
yarn add @samline/debounce

bun

Terminal
bun add @samline/debounce

HTML / CDN

Terminal
<script src="https://cdn.jsdelivr.net/npm/@samline/debounce@1.0.2/dist/browser/debounce.global.js" defer></script>
2

Add markup

A field and a status line. No special attributes are required.

index.html
<label for="search">Search</label>
<input id="search" type="search" autocomplete="off" />
<p id="status">Type to search.</p>
3

Debounce the handler

main.js
import { debounce } from '@samline/debounce'

const input = document.querySelector('#search')
const status = document.querySelector('#status')

const search = debounce(query => {
  status.textContent = query ? `Searching for “${query}”…` : 'Type to search.'
}, 300)

input.addEventListener('input', () => search(input.value))
Copy complete working files

Continue with leading, trailing, maxWait and the returned controls.

Explore the options
04 / Beyond search

Pick the right tool.
Keep the call count low.

Three common jobs, each with the right tool.

flush()

Submit without waiting

Run the pending search immediately when the form is submitted.

Read the API
main.js
form.addEventListener('submit', () => search.flush())
throttle

Autosave at a steady pace

Save at most once per second while the user keeps typing.

Read the options
main.js
const save = throttle(() => persist(editor.value), 1000)
editor.addEventListener('input', save)
rafThrottle

Measure once per frame

Coalesce scroll events into one layout read per animation frame.

Read the API
main.js
const update = rafThrottle(() => bar.style.width = progress() + '%')
window.addEventListener('scroll', update, { passive: true })
Explore working examples
05 / Before you build

A few details. Clearly answered.

When should I use throttle instead of debounce?
Use debounce when only the final value matters, like search. Use throttle when the work must keep happening during a burst, like autosave or progress updates.
Does it work without a bundler?
Yes. Load dist/browser/debounce.global.js with a classic script tag and use window.Debounce. Pin the version in production.
What changed in 1.0?
throttle, rafThrottle and pending() are new, debounce forwards this, maxWait is clamped to wait and the Svelte store fixes chained updates. The changelog lists every change.
Is there a React hook?
Yes. useDebouncedCallback and useThrottledCallback from @samline/debounce/react return a stable function that always calls the latest callback and cancels on unmount; useDebouncedValue debounces a value.
How do I stop a pending call when a component or dialog closes?
Call cancel() on the returned function. The React, Vue and Svelte adapters do it for you on unmount or scope disposal.
Does the debounced function return a value?
It returns the result of the last invocation, and flush() returns the result of the call it runs. Before the first invocation the result is undefined.
Is it safe to import during server rendering?
Yes. Nothing touches the DOM at import time, and rafThrottle falls back to a 16 ms timer when requestAnimationFrame does not exist.
How big is it?
The root entry is under 1 KB gzip and has no dependencies. Every entry point has a size budget checked in CI.
Fewer calls, less work

Make every call count.

Try the examples or follow the first steps.

Guides, the complete API and release notes, in one place.

Read the documentation