react-hotkeys-hook

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

Library
npm
v5.3.3
3,505stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
87/100Excellent
Development Activity92
Maintenance96
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
92/100Excellent
Architecture90
Code Quality90
Innovation95
Learning Curve90

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 44 apps in this directory

TypeScript
94%
MIT

Actual

Invoicing Finance

28,224

Local-first personal finance with envelope budgeting, end-to-end encryption, and multi-device sync — no subscription required.

View details
93
Repo Health
85
Technical
77
Dependency
Built with
TypeScript94%
Updated yesterday
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,010

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
61
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 1 months ago
TypeScript
51%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,087

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
69
Dependency
Built with
TypeScript51%
Rust38%
Updated today
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,846

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
91
Repo Health
77
Technical
64
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
53%
Other

Chaskiq

CRM · Customer Support

3,560

Self-hosted live chat, video calls, help center, and marketing automation — a full-stack Intercom alternative you run on your own infrastructure.

View details
60
Repo Health
66
Technical
68
Dependency
Built with
TypeScript53%
Ruby36%
Updated 1 months ago
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

50,753

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
88
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today
TypeScript
45%
Other

Convex Backend

Developer Tools · Databases

12,394

Open-source reactive database that lets developers build live-updating apps with pure TypeScript, strong consistency, and real-time subscriptions—no separate API layer required.

View details
88
Repo Health
82
Technical
70
Dependency
Built with
TypeScript45%
Rust43%
Updated today
TypeScript
92%
AGPL 3.0

Documenso

Digital Signiture

14,603

Self-hosted, open-source DocuSign alternative with legally binding PDF signatures, multi-party workflows, and a full REST and tRPC API.

View details
93
Repo Health
79
Technical
72
Dependency
Built with
TypeScript92%
Updated today

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

Search