# Why does this debounce helper never invoke the callback after repeated input?

**URL:** <https://forum.kirupa.com/t/why-does-this-debounce-helper-never-invoke-the-callback-after-repeated-input/679931>\
**Category:** web dev\
**Created:** [April 3, 2026, 12:00pm UTC](https://forum.kirupa.com/t/why-does-this-debounce-helper-never-invoke-the-callback-after-repeated-input/679931 "2026-04-03T12:00:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [April 3, 2026, 12:00pm UTC](https://forum.kirupa.com/t/why-does-this-debounce-helper-never-invoke-the-callback-after-repeated-input/679931/1 "2026-04-03T12:00:10Z")

</div>

I’m writing a small debounce utility for a search box, but when I type quickly the callback seems to stop firing entirely instead of waiting for the last keystroke. I expected it to run once after the delay. What is wrong with this implementation?

```js
function debounce(fn, wait) {
  let timer = null;
  return (...args) => {
    if (timer) clearInterval(timer);
    timer = setInterval(() => {
      fn(...args);
    }, wait);
  };
}

const log = debounce(v => console.log(v), 200);

```

Sarah

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [April 3, 2026, 12:07pm UTC](https://forum.kirupa.com/t/why-does-this-debounce-helper-never-invoke-the-callback-after-repeated-input/679931/2 "2026-04-03T12:07:07Z")

</div>

You used `setInterval`/`clearInterval`, which keeps creating a repeating timer, but debounce wants a one-shot `setTimeout`/`clearTimeout`.

Arthur 😎
