> ## Content Index
> Fetch the complete content index at: https://www.namastesalesforce.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# LWC: debounce a lightning-input
- URL: https://www.namastesalesforce.com/snippets/lwc-debounce-input/
- Published: 2026-04-29T09:00:00.000Z
- Updated: 2026-04-29T09:00:00.000Z
- Description: Stop hammering the server on every keystroke — 300 milliseconds of patience per search box.
- Author: Swarnil Singhai
- Tags: #snippet, #snippet-lang-js, LWC, #Import 2026-09-03 19:13

```javascript
import { LightningElement } from 'lwc';

const DELAY = 300;

export default class ContactSearch extends LightningElement {
    delayTimeout;

    handleKeyChange(event) {
        window.clearTimeout(this.delayTimeout);
        const searchKey = event.target.value;
        this.delayTimeout = window.setTimeout(() => {
            this.dispatchEvent(
                new CustomEvent('search', { detail: { searchKey } })
            );
        }, DELAY);
    }
}
```

Stop hammering the server on every keystroke — 300 milliseconds of patience per search box.

## Gotchas

Read event.target.value BEFORE the timeout — the event is recycled by the time the callback runs. Clear the timeout in disconnectedCallback too if the component can unmount mid-typing.