# use-hotkeys

> ![npm](https://img.shields.io/npm/dt/use-hotkeys.svg) ![npm](https://img.shields.io/npm/v/use-hotkeys.svg) ![NpmLicense](https://img.shields.io/npm/l/use-hotkeys.svg)

Latest version **1.1.0** (published 2019-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-hotkeys
pnpm add use-hotkeys
yarn add use-hotkeys
bun add use-hotkeys
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-03-31 |
| First published | 2019-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | alexsandiyarov |

## Links

- npm: https://www.npmjs.com/package/use-hotkeys
- npm.io page: https://npm.io/package/use-hotkeys

## Dependencies (1)

- [hotkeys-js](https://npm.io/package/hotkeys-js.md) 3.4.4

## Recent versions

- 1.1.0 (latest) — 2019-03-31
- 1.0.2 — 2019-03-31
- 1.0.1 — 2019-02-25
- 1.0.0 — 2019-02-25
- 0.0.1 — 2019-02-25
- 0.0.0 — 2019-02-22

## README

# Use Hotkeys

![npm](https://img.shields.io/npm/dt/use-hotkeys.svg)
![npm](https://img.shields.io/npm/v/use-hotkeys.svg)
![NpmLicense](https://img.shields.io/npm/l/use-hotkeys.svg)

React wrapper around [Hotkeys.js](https://github.com/jaywcjlove/hotkeys).

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

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

Read about [Hooks](https://reactjs.org/docs/hooks-intro.html) feature.

## Installation

> Note: React 16.8+ is required for Hooks.

### With npm

```sh
npm i use-hotkeys
```

### Or with yarn

```sh
yarn add use-hotkeys
```

## Usage

[![Edit 1llx4n8q4](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/1llx4n8q4?fontsize=14)

```jsx
import useHotkeys from 'use-hotkeys';
```

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

---
_Source: https://npm.io/package/use-hotkeys · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
