react-hotkeys-hook

A lightweight React hook for wiring up keyboard shortcuts in components declaratively.

Library
npm
v5.3.3
3,504 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 84
Maintenance 88
Community 60
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
92 /100 Excellent
Architecture 90
Code Quality 90
Innovation 95
Learning Curve 90

react-hotkeys-hook is a small, dependency-free React hook that lets you bind keyboard shortcuts to component logic in a declarative way. A single useHotkeys(keys, callback) call registers combinations like ctrl+k or shift+a, handles modifier keys across platforms, and cleans itself up on unmount.

Beyond the basic hook it ships scopes for grouping and toggling shortcuts, focus-trapping so a hotkey only fires when a specific element is focused, form-aware filtering that prevents accidental triggers while typing, and a useRecordHotkeys hook for capturing user-defined key bindings. It is written in TypeScript and works with any React 16.8+ application.

What You Get

  • The useHotkeys(keys, callback, options, deps) hook for declarative shortcut binding
  • A HotkeysProvider plus useHotkeysContext for grouping shortcuts into activatable scopes
  • Focus trapping, form-tag filtering, and contentEditable handling out of the box
  • useRecordHotkeys for capturing user-defined key combinations and isHotkeyPressed for imperative checks
  • First-class TypeScript types and a documented options API

Common Use Cases

  • Adding application-wide shortcuts like a command palette (ctrl+k) or save (mod+s)
  • Scoping shortcuts to specific views or modals so they do not collide
  • Building a settings UI that lets users record and remap their own key bindings
  • Restricting a shortcut to a focused element such as an editable region or list item

Under The Hood

Architecture - The library is a small, focused set of modules under packages/react-hotkeys-hook/src/lib. useHotkeys.ts is the core hook: it normalizes the keys/options/deps arguments, memoizes the callback and options (via useDeepEqualMemo), keeps mutable function options in refs to avoid re-registering listeners, and attaches a keydown/keyup handler that matches events against parsed hotkeys. parseHotkeys.ts turns strings like ctrl+k into a normalized Hotkey shape and maps physical key codes to canonical names (including macOS detection for the mod alias). validators.ts centralizes the predicates that decide whether a hotkey should fire (enabled, scope active, tag allowed, event matches). HotkeysProvider.tsx supplies scope state through context, isHotkeyPressed.ts tracks currently-pressed keys as module-level state for imperative checks, and useRecordHotkeys.ts captures live key presses for remapping UIs. index.ts re-exports the public surface.

Tech Stack - Written almost entirely in TypeScript (99%), distributed as an ESM package with sideEffects: false for tree-shaking. React and react-dom are peer dependencies (>=16.8.0) and it ships with zero runtime dependencies. The build uses Vite with vite-plugin-dts for type emission, the repo is an npm-workspaces monorepo (the library plus a documentation site), tests run on Vitest with Testing Library and jsdom, and Biome handles formatting and linting.

Code Quality - The src/test directory holds five test suites covering the hook, context/provider, recording, and pressed-key tracking against a jsdom environment. Types are declared explicitly in types.ts (e.g. Keys, Options, HotkeysEvent, FormTags) and the public API is fully typed. The core hook contains explanatory comments around its trickiest concern - keeping callbacks and options current in refs without re-registering event listeners - which shows deliberate handling of a common React footgun.

API Design - The public surface is intentionally tiny and ergonomic: useHotkeys(keys, callback, options?, deps?) covers the common case in one line, mirroring the familiar useCallback dependency-array convention so React developers need almost no ramp-up. Naming is consistent (useHotkeysContext, useRecordHotkeys, isHotkeyPressed), advanced behavior is opt-in through a documented Options object, and the project backs it with a dedicated documentation site and live examples, keeping the barrier to getting started very low.

Used by 45 apps in this directory

JavaScript
99%
AGPL 3.0

drawDB

Databases

40,114

Design database schemas visually in your browser and export executable SQL for any major database — no account required.

View details
78
Repo Health
70
Technical
73
Dependency
Built with
JavaScript 99%
Updated 6 days ago
Python
82%
GPL 3.0

ERPNext

ERP · Invoicing Finance

40,517

100% free, open-source ERP unifying accounting, manufacturing, inventory, CRM, HR, and POS in a single self-hostable platform.

View details
96
Repo Health
77
Technical
74
Dependency
Built with
Python 82%
JavaScript 13%
Updated 5 days ago
TypeScript
54%
Other

Focalboard

Collaboration · Productivity · Project Management

26,522

Self-hosted, open source project management with Kanban, table, gallery, and calendar views — a privacy-first alternative to Trello, Notion, and Asana.

View details
56
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 54%
Go 40%
Updated 5 months ago
Go
62%
Apache 2.0

Harness Open Source

Code Editors · Developer Tools · Devops

38,684

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
Go 62%
TypeScript 33%
Updated 6 days ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,384

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
76
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 6 days ago
TypeScript
97%
MIT

HyperDX

Analytics · Developer Tools · Monitoring

9,963

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
89
Repo Health
83
Technical
64
Dependency
Built with
TypeScript 97%
Updated 5 days ago
TypeScript
100%
Apache 2.0

ILLA Builder

Design Tools · Developer Tools · Low Code Platforms

12,333

Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.

View details
55
Repo Health
71
Technical
63
Dependency
Built with
TypeScript 100%
Updated 5 months ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,433

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
88
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers