Installation
Via Package Manager
To install the package we use our favorite package manager.
- NPM
- Bun
- Yarn
yarn add react-hotkeys-hook
npm i react-hotkeys-hook --save
bun i react-hotkeys-hook
import { useHotkeys } from 'react-hotkeys-hook';
Via CDN
To use the ES Module we can reference it directly from unpkg.com:
import { useHotkeys } from 'https://unpkg.com/browse/react-hotkeys-hook@5.0.0/dist/react-hotkeys-hook.esm.js';
Live Editor
function MyComponent() { const [count, setCount] = useState(0); useHotkeys('a', () => setCount(count => count + 1)); return ( <span>Pressed 'a' key {count} times.</span> ); }
Result
Loading...