A custom React hook to fire an event when user press one, or more specific keys.
npm i @bscop/use-keydown
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.
Read the guidelines.
npm test
Coverage reports are hosted on codecov.
npm run badge:coverage -- --token=<guid>
Bruno Scopelliti
www.brunoscopelliti.com