Quick Start
The fastest way to get you going.
Install
- pnpm
- bun
- npm
- yarn
pnpm add react-hotkeys-hook@3
bun add react-hotkeys-hook@3
npm i react-hotkeys-hook@3 --save
yarn add react-hotkeys-hook@3
Note: React 16.8+ is required to use Hooks.
Usage
import { useHotkeys } from 'react-hotkeys-hook'
function MyComponent() {
const [count, setCount] = useState(0)
useHotkeys('a', () => setCount((count) => count + 1))
return <span>Pressed 'a' key {count} times.</span>
}
Out of the box support for TypeScript
react-hotkeys-hook is written in TypeScript, so we don't have to install any additional typings.