@lindeneg/on-key
v1.1.4
Published
Hook to listen for key-strokes and then do something.
Downloads
48
Maintainers
Readme
@lindeneg/on-key
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 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
import useOnKey from '@lindeneg/on-key';
function SomeComponent() {
useOnKey('ArrowRight', (event) => console.log('ArrowRight: keydown', event));
}