@bscop/use-keydown
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

use-keydown

GitHub license npm version CircleCI Status Coverage

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 to false 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

Package Sidebar

Install

npm i @bscop/use-keydown

Weekly Downloads

61

Version

1.0.3

License

MIT

Unpacked Size

12.2 kB

Total Files

9

Last publish

Collaborators

  • brunoscopelliti