Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Hotkeys API Reference
Hotkey Sequence API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Normalization & format API Reference
Hotkeys API Reference

useHotkeys

Function: useHotkeys()

ts
function useHotkeys(hotkeys, commonOptions): void;

Defined in: useHotkeys.ts:73

Preact hook for registering multiple keyboard hotkeys at once.

Uses the singleton HotkeyManager for efficient event handling. Accepts a dynamic array of hotkey definitions, making it safe to use with variable-length lists without violating the rules of hooks.

Options are merged in this order: HotkeysProvider defaults < commonOptions < per-definition options

Callbacks and options are synced on every render to avoid stale closures.

Parameters

hotkeys

UseHotkeyDefinition[]

Array of hotkey definitions to register

commonOptions

UseHotkeyOptions = {}

Shared options applied to all hotkeys (overridden by per-definition options). Per-row enabled: false still registers that hotkey: HotkeyManager suppresses execution only (the row stays in the store and appears in TanStack Hotkeys devtools). Toggling enabled updates the existing handle via setOptions (no unregister/re-register churn).

Returns

void

Examples

tsx
function Editor() {
  useHotkeys([
    { hotkey: 'Mod+S', callback: () => save() },
    { hotkey: 'Mod+Z', callback: () => undo() },
    { hotkey: 'Escape', callback: () => close() },
  ])
}
tsx
function MenuShortcuts({ items }) {
  // Dynamic hotkeys from data -- safe because it's a single hook call
  useHotkeys(
    items.map((item) => ({
      hotkey: item.shortcut,
      callback: item.action,
      options: { enabled: item.enabled },
    })),
    { preventDefault: true },
  )
}