@react-hook/hotkey

A React hook for invoking a callback when hotkeys are pressed

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@react-hook/hotkey
1,250323.1.03 years ago3 years agoMinified + gzip package size for @react-hook/hotkey in KB

Readme


useHotkey()

<img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@react-hook/hotkey?style=for-the-badge&labelColor=24292e">
<img alt="Types" src="https://img.shields.io/npm/types/@react-hook/hotkey?style=for-the-badge&labelColor=24292e">
<img alt="NPM Version" src="https://img.shields.io/npm/v/@react-hook/hotkey?style=for-the-badge&labelColor=24292e">
<img alt="MIT License" src="https://img.shields.io/npm/l/@react-hook/hotkey?style=for-the-badge&labelColor=24292e">


npm i @react-hook/hotkey


A React hook for invoking a callback when hotkeys are pressed. This hook also provides interop between event.key and event.which - you provide a string, and the library turns it into an event.which key code if it has to.
For better TypeScript support, this library doesn't have a special syntax à la the is-hotkey package. It uses plain JS objects and your build will fail if you've included a typo.

Quick Start

```jsx harmony import as React from 'react' import {useHotkey, useHotkeys} from '@react-hook/hotkey'
const OneHotkey = () => { const ref = React.useRef(null) const save = () => {} // creates a hotkey for Command|Control + S keys useHotkey(ref, 'mod', 's'
, save) return