React hook for handling keyboard events.
npm install @mvdlei/hooks
import React from "react"; import { useKey } from "@mvdlei/hooks"; const App = () => { const [count, setCount] = React.useState(0); useKey("ArrowUp", () => setCount(count + 1)); useKey("ArrowDown", () => setCount(count - 1)); return ( <div> <h1>Count: {count}</h1> </div> ); };
useKey(key: string, callback: () => void): void;
use-key.ts