An open API service indexing awesome lists of open source software.

https://github.com/lucleray/keypress

⌨ a react hook for keypress events
https://github.com/lucleray/keypress

hooks keyboard keypress react

Last synced: about 2 months ago
JSON representation

⌨ a react hook for keypress events

Awesome Lists containing this project

README

          

# `@rehooks/keypress`

> React hook for keypress events at the `window` level

> **Note:** This is using the new [React Hooks API Proposal](https://reactjs.org/docs/hooks-intro.html)
> which is subject to change until React 16.7 final.
>
> You'll need to install `react`, `react-dom`, etc at `^16.7.0-alpha.0`

## Install

```sh
yarn add @rehooks/keypress
```

## Usage

```js
import useKeyPress from '@rehooks/keypress';

function MyComponent() {
const [keys, setKeys] = useState([]);

function handleKeyPress({ key }) {
setKeys(keys => [key, ...keys]);
}

useKeyPress(handleKeyPress);

return (


Last keys pressed



    {keys.map(key => (
  • {key}

  • ))}


);
}
```

⚡️ And you get a simple keylogger component :