# react-hook-mousetrap

> A react hook to trigger callbacks on specified key combo with mousetrap

Latest version **2.0.4** (published 2020-10-27) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2020-10-27 |
| First published | 2019-01-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/react-hook-mousetrap) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 2.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | olup otilapan |
| Maintainers | olup |
| Keywords | react, hook, mousetrap, keys, combo, hotkeys |

## Links

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

## Dependencies (1)

- [mousetrap](https://npm.io/package/mousetrap.md) ^1.6.2

## 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

- 2.0.4 (latest) — 2020-10-27
- 2.0.3 — 2020-06-23
- 2.0.2 — 2019-02-06
- 2.0.1 — 2019-02-05
- 2.0.0 — 2019-02-05
- 1.0.1 — 2019-02-03
- 1.0.0 — 2019-01-30

## README

# react-hook-mousetrap

A quick react hook to trigger actions on specific key combination. It uses [mousetrap](https://github.com/ccampbell/mousetrap) to do the job, so any mousetrap combo or array of combo can be passed as option.

Import it like this :

```
import useMousetrap from "react-hook-mousetrap"
```

Then in your component :

```
// useMousetrap(<Keys>, <Callback>)
useMousetrap("ctrl+enter", // any mousetrap combo, or array of combo

      () => { // triggered on key combo
        // whatever. You can use your state in there too.
      });
```

**NOTE : If you want to trap keys in an `input` or `textarea` you need to add the mousetrap class to the element : `className="mousetrap"`**

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