key-hooks

1.1.1 • Public • Published

key-hooks

React hooks for keypress handling.

Example usage

key-hooks example

import React from "react";
import { useKeyPressed } from "key-hooks";
import { useKeyToggle } from "key-hooks";
 
export default function App() {
  const [keyDown] = useKeyPressed("Shift"); // param array ["Shift"] also works
  const [keyState] = useKeyToggle(["a", "b", "c"]); // multiple keys
  return (
    <div className="App">
      <h1>key-hooks example</h1>
      <p>Shift key is: {keyDown ? "DOWN" : "UP"}</p>
      <p>Toggle state with a, b, c key: {keyState ? "ON" : "OFF"}</p>
    </div>
  );
}

Reference

Readme

Keywords

none

Package Sidebar

Install

npm i key-hooks

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

5.64 kB

Total Files

11

Last publish

Collaborators

  • andygock