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
- Host: GitHub
- URL: https://github.com/lucleray/keypress
- Owner: lucleray
- License: mit
- Created: 2018-10-26T09:11:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-26T09:24:48.000Z (over 7 years ago)
- Last Synced: 2025-10-11T06:21:17.480Z (8 months ago)
- Topics: hooks, keyboard, keypress, react
- Language: JavaScript
- Homepage:
- Size: 163 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 :