A higher-order component and decorator for React that binds keyboard events to components and methods. Current stable version is 1.9.12. It uses a declarative syntax to define key bindings, supports modifier keys, scopes events to active components, and adds only a single document listener regardless of the number of bindings. Released as CommonJS, with a separate UMD branch. Compared to alternatives like react-hotkeys, it is lighter (2KB gzipped) and simpler, with direct method decoration but less flexibility in key combinations and sequencing.
npm install react-keydownNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates decorating a method with @keydown('enter') to increment a counter when Enter is pressed.
Consider using react-hotkeys or react-use-gesture as alternatives.
Install and configure the decorator plugin, or use the HOC pattern: keydown('enter')(MyComponent).Ensure components are properly focused or clicked to receive events; consider using event.stopPropagation if needed.
Run 'npm install --save react-keydown'
Install @babel/plugin-proposal-decorators and add to .babelrc: { 'plugins': ['@babel/plugin-proposal-decorators', { 'legacy': true }] }