# react-hotkey-hook

> A react hook which can execute any function for any keyboard shortcut.

Latest version **1.0.3** (published 2023-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-hotkey-hook
pnpm add react-hotkey-hook
yarn add react-hotkey-hook
bun add react-hotkey-hook
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-05-14 |
| First published | 2021-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Pranav Doshi |
| Maintainers | pranavdoshi |
| Keywords | react, react-hotkey, react-hotkeys, react-hotkey-hook, react-hotkeys-hook, hotkeys, hotkey, hotkey-hook, keyboard-shortcuts |

## Links

- npm: https://www.npmjs.com/package/react-hotkey-hook
- Repository: https://github.com/ZaphodElevated/react-hotkey-hook
- Homepage: https://github.com/ZaphodElevated/react-hotkey-hook#readme
- Issues: https://github.com/ZaphodElevated/react-hotkey-hook/issues
- npm.io page: https://npm.io/package/react-hotkey-hook

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2023-05-14
- 1.0.2 — 2021-11-13
- 1.0.1 — 2021-11-13
- 1.0.0 — 2021-11-06

## README

# React Hotkey Hook

A react hook which can execute any function for any keyboard shortcut.

# Installation

Install the package with npm or yarn with either of the following commands.

```
npm i react-hotkey-hook
```

```
yarn add react-hotkey-hook
```

Make sure to import the useHotkey hook from the library after it is installed

```js
import useHotkey from "react-hotkey-hook";
```

# Usage

```js
import "./App.css";
import React from "react";
import useHotkey from "react-hotkey-hook";

function App() {
  const onKeyPress = () => {
    console.log("key pressed");
  };

  useHotkey("Control+a", true, onKeyPress);

  useHotkey("Shift+A", true, onKeyPress);

  return (
    <div className="container">
      <h1>Example for React Hotkey Hook</h1>
    </div>
  );
}

export default App;
```

# Options

All options are optional and have a default value which you can override to change the behavior of the hook.

| Option     | Type         | Description                                                            |
| ---------- | ------------ | ---------------------------------------------------------------------- |
| `hotkeys`  | `string`     | The combination of hotkeys.                                            |
| `overide`  | `boolean`    | Optional Parameter. Prevents default event when true. True on default. |
| `callback` | `() => void` | Function that will be called when the combination of keys are pressed. |

# License

Distributed under the MIT License. See `LICENSE` for more information.

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