React Shortcuts (version 2.1.0) is a library designed to manage keyboard shortcuts declaratively within React components. It provides a structured way to define application-wide and component-specific keymaps, which can include platform-specific variations and sequences. The library uses `mousetrap` (Combokeys) under the hood for robust key detection. Key differentiators include centralizing shortcut definitions and abstracting away boilerplate `addEventListener`/`removeEventListener` logic. However, the package is effectively abandoned, with its last release over 7 years ago and no recent development activity. It relies heavily on React's now-deprecated Legacy Context API (`getChildContext`), making it incompatible with modern React versions (17 and above).
npm install react-shortcutsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining a keymap, creating a ShortcutManager, providing it via `getChildContext` in a parent component, and consuming shortcuts in a child component using the `<Shortcuts>` component. It shows basic shortcut actions and platform-specific keybindings.
There is no direct fix for this library to work with modern React without significant re-architecture. Consider migrating to a modern keyboard shortcut library that uses the new Context API or React Hooks, such as `react-hotkeys-hook` or `@keybindy/react`.
Upgrade to a modern keyboard shortcut library compatible with your React version, or pin your project to an older React version (e.g., React 16) which is generally not recommended for new development.
Avoid using this library for new projects. For existing projects, plan for migration to an actively maintained alternative.
Thoroughly test shortcut interactions across your application, particularly when multiple components might capture the same keys or when integrating with other keyboard-event-driven features. Consider using `stopPropagation` and `preventDefault` as needed within your handlers.
Ensure that a parent component (`App` in the quickstart) implements both `getChildContext` to return the `shortcutManager` and `childContextTypes` to declare its type (`PropTypes.object.isRequired`). Verify that your React version is compatible (React 16 or earlier).
This warning signals fundamental incompatibility with modern React. The primary 'fix' is to migrate away from `react-shortcuts` to a modern library that does not use the Legacy Context API.
Verify that `import { Shortcuts } from 'react-shortcuts'` is correct and that the `react-shortcuts` package is installed and accessible in your environment. Check for any build or bundling issues that might prevent the component from being resolved.