@bscop/use-keydown
v1.0.3
Published
A custom React hook to fire an event when user press one, or more specific keys.
Downloads
113
Maintainers
Readme
use-keydown
A custom React hook to fire an event when user press one, or more specific keys.
Install
npm i @bscop/use-keydown
Usage
Default behavior:
import useKeydown from "@bscop/use-keydown";
useKeydown(
(event) => {
console.log(">", event.code);
}
);
Custom behavior:
import useKeydown from "@bscop/use-keydown";
useKeydown(
(event) => {
console.log(">", event.code);
},
{
active: true,
keys: [
"ArrowUp",
"ArrowDown"
]
}
);
active
: when is set tofalse
the hook won't register the event listener.keys
: defines the key codes for which the handler will be executed. You can omit it, to listen for all the possible keys.
Contribute
Read the guidelines.
Run tests
npm test
Coverage
Coverage reports are hosted on codecov.
npm run badge:coverage -- --token=<guid>
Bruno Scopelliti
www.brunoscopelliti.com