React wrapper around Hotkeys.js.
╭┈┈╮ ╭┈┈╮ ╭┈┈╮
┆ ├┈┈..┈┈┈┈┈.┆ └┈╮┆ ├┈┈..┈┈┈┈┈..┈┈.┈┈..┈┈┈┈┈.
┆ ┆┆ □ ┆┆ ┈┤┆ < ┆ -__┘┆ ┆ ┆┆__ ┈┈┤
╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈┈╯╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈ ┆╰┈┈┈┈┈╯
╰┈┈┈┈┈╯
Use Hotkeys - React hook that listen to keyboard events, defining and dispatching keyboard shortcuts.
Read about Hooks feature.
Note: React 16.8+ is required for Hooks.
npm i use-hotkeys
yarn add use-hotkeys
import useHotkeys from 'use-hotkeys';
const Counter = () => {
const [count, setCount] = React.useState(0);
useHotkeys(
(key, event, handle) => {
switch (key) {
case 'up':
return setCount(count + 1);
case 'down':
return setCount(count - 1);
default:
return setCount(count);
}
},
['up', 'down'],
[count]
);
return <div>{count}</div>;
};