Skip to main content
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 delay ms, across every input method.
  • Held-key suppression — repeated keydown from 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 value prop changes from outside, the input re-syncs and any stale in-flight commit is cancelled.
By default all four user actions (typing, Enter, paste, clear) can commit; the triggers option lets you opt out of any of them.

Installation

Usage

Call the hook with the controlled value, 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

Pass triggers to restrict which user actions fire a commit. When omitted, all are active.
For example, to commit only on Enter, paste, and clear — never on a typing pause:

Behavior reference

Last modified on July 24, 2026