useInputGuards sits between a text input’s raw events and an expensive onCommit callback — a network request, store update, or analytics event you don’t want firing on every keystroke. The visible value stays fully responsive while the hook decides when a value is worth committing. The “guards” in the name are the protections it layers over that callback:
- Debounce — a burst of typing coalesces into a single commit with the final value.
- Commit guard — commits are rate-limited to at most one per
delayms, across every input method. - Held-key suppression — repeated
keydownfrom a held hotkey is dropped, so holding Enter or a paste shortcut doesn’t fire repeatedly. - Deduplication — the same value never commits twice in a row.
- External sync — when the
valueprop changes from outside, the input re-syncs and any stale in-flight commit is cancelled.
triggers option lets you opt out of any of them.
Installation
Usage
Call the hook with the controlledvalue, a delay, and your onCommit handler, then spread the returned inputProps onto the input. The hook owns the visible value and the commit timing; your component just reacts to commits.
inputProps carries value, onChange, onPaste, and onKeyDown. Spread all of them — the paste and keydown handlers are what make the guards work; dropping them falls back to plain debounced typing.
Configuration
Choosing which actions commit
Passtriggers to restrict which user actions fire a commit. When omitted, all are active.