use-hotkeys
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Use Hotkeys

npm npm NpmLicense

React wrapper around Hotkeys.js.

╭┈┈╮          ╭┈┈╮  ╭┈┈╮
┆  ├┈┈..┈┈┈┈┈.┆  └┈╮┆  ├┈┈..┈┈┈┈┈..┈┈.┈┈..┈┈┈┈┈.
┆     ┆┆  □  ┆┆   ┈┤┆    < ┆  -__┘┆  ┆  ┆┆__ ┈┈┤
╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈┈╯╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈  ┆╰┈┈┈┈┈╯
                                  ╰┈┈┈┈┈╯

Use Hotkeys - React hook that listen to keyboard events, defining and dispatching keyboard shortcuts.

Read about Hooks feature.

Installation

Note: React 16.8+ is required for Hooks.

With npm

npm i use-hotkeys

Or with yarn

yarn add use-hotkeys

Usage

Edit 1llx4n8q4

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>;
};

Readme

Keywords

none

Package Sidebar

Install

npm i use-hotkeys

Weekly Downloads

7

Version

1.1.0

License

MIT

Unpacked Size

4.33 kB

Total Files

6

Last publish

Collaborators

  • alexsandiyarov