Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/patrikmasiar/react-keyboard-key

Container and hook with keyboard event listener.
https://github.com/patrikmasiar/react-keyboard-key

node-module npm package react typescript

Last synced: 11 days ago
JSON representation

Container and hook with keyboard event listener.

Awesome Lists containing this project

README

        

[![npm](https://img.shields.io/npm/v/react-keyboard-key?style=plastic)](https://www.npmjs.com/package/react-keyboard-key)
[![NPM](https://img.shields.io/npm/l/react-keyboard-key)](https://github.com/patrikmasiar/react-keyboard-key/blob/master/LICENSE)
[![NPM](https://img.shields.io/npm/dy/react-keyboard-key?style=plastic)](https://www.npmjs.com/package/react-keyboard-key)

# react-keyboard-key
Container and hook with keyboard event listener.

## Usage

#### Types
```javascript
keyInfo: {
key: string | null;
code: string | null;
keyCode: number | null;
output: KeyboardEvent | null,
};
addKeyListener: () => void;
removeEventListener: () => void;
onKeyDownCallback: (event: KeyboardEvent) => void;
```

### Container
```javascript
import { KeyListenerContainer } from 'react-keyboard-key';

...

const ExampleComponent: FC = ({ children }) => {
return (
{
e.preventDefault();
}}
>
{keyInfo => (


{keyInfo.code}

)}

);
};

```

### Hook
```javascript
import { useKeyboardKey } from 'react-keyboard-key';

const ExampleComponent: FC = () => {
const { keyInfo } = useKeyboardKey(onKeyDownCallback);

const onKeyDownCallback = (e: KeyboardEvent) => {
e.preventDefault
};

return (


{keyInfo.code}

);
};
```

## Project
* [whatdidipress.com](https://whatdidipress.com/)
* [Github project whatdidipress.com](https://github.com/patrikmasiar/what-did-i-press/)