# @lindeneg/on-key

> Hook to listen for key-strokes and then do something.

Latest version **1.1.4** (published 2022-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lindeneg/on-key
pnpm add @lindeneg/on-key
yarn add @lindeneg/on-key
bun add @lindeneg/on-key
```

## 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.4 |
| Published | 2022-02-13 |
| First published | 2022-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | lindeneg |
| Maintainers | christianlindeneg |
| Keywords | react, hook, react-hooks, keys, events, typescript, key-event |

## Links

- npm: https://www.npmjs.com/package/@lindeneg/on-key
- Repository: https://github.com/Lindeneg/lindeneg-npm-packages
- Homepage: https://github.com/lindeneg/lindeneg-npm-packages/tree/master/packages/on-key
- Issues: https://github.com/Lindeneg/lindeneg-npm-packages/issues
- npm.io page: https://npm.io/package/@lindeneg/on-key

## 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.1.4 (latest) — 2022-02-13
- 1.1.3 — 2022-01-30
- 1.1.2 — 2022-01-29
- 1.1.1 — 2022-01-23
- 1.1.0 — 2022-01-23
- 1.0.4 — 2022-01-20
- 1.0.3 — 2022-01-20
- 1.0.2 — 2022-01-16
- 1.0.1 — 2022-01-16
- 1.0.0 — 2022-01-16

## README

### @lindeneg/on-key

![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label) ![bundle-size](https://badgen.net/bundlephobia/min/@lindeneg/on-key) ![license](https://badgen.net/npm/license/@lindeneg/on-key)

[Sandbox](https://codesandbox.io/s/lindeneg-on-key-m99cq)

---

React hook to listen for key-strokes and then do something

### Installation

`yarn add @lindeneg/on-key`

---

#### Arguments

| Name     | Required | Default     | Type                                | Description                                                                                                        |
| -------- | -------- | ----------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| key      | Y        | -           | `string`                            | [KeyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) to listen after |
| callback | Y        | -           | `(event: KeyboardEvent) => void`    | function to be called when desired event is dispatched                                                             |
| type     | N        | `"keydown"` | `"keydown" \| "keyup" \| "pressed"` | event type to listen after                                                                                         |

#### Usage

```tsx
import useOnKey from '@lindeneg/on-key';

function SomeComponent() {
  useOnKey('ArrowRight', (event) => console.log('ArrowRight: keydown', event));
}
```

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