A React hook for declaratively handling keyboard shortcuts in components. Current stable version is 5.3.0, released with monthly cadence. It ships TypeScript definitions, supports scopes to prevent hotkey collisions, focus traps, and enables/disables scopes via context. Unlike alternatives like react-hotkeys (maintenance mode) or mousetrap (no React hook), this library is React-first with a simple hook API. Requires React >= 16.8.0. Bundle size is minimal (~2KB gzipped). ESM and CJS exports available.
npm install react-hotkeys-hookNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic example using useHotkeys with a scope dependency array. Shows increment on Ctrl+K press.
Rename enabledScopes prop to activeScopes. For custom key mappings, use key codes (e.g., 'KeyK' instead of 'k').
Use '+' exclusively to combine keys. For chord sequences, use array syntax.
Update options to use new property names as per v5 migration guide.
Pass { enabled: true } or { scopes: ['global'] } to listen globally.Pass deps array as third argument or use functional state updates.
Rename 'enabledScopes' to 'activeScopes' in HotkeysProvider.
Wrap your app with <HotkeysProvider> or avoid using context outside it.
Always call useHotkeys unconditionally; use scopes or enabled option for conditional behavior.
Use 'Meta+k' for Cmd key, or 'Control+k' for Ctrl. 'mod' is an alias but not documented.