1.0.5 • Published 5 years ago
@react-typed-hooks/use-key-press v1.0.5
useKeyPress
React hook that returns true when the specified targetKey is pressed.
Installation
npm install @react-typed-hooks/use-key-pressUsage
import { useKeyPress } from "@react-typed-hooks/use-key-press";
const Demo = () => {
const isEscapePressed = useKeyPress({ targetKey: "Escape" });
return isEscapePressed ? "Yes" : "No";
};API
Types
interface UseKeyPressOptions {
targetKey: KeyboardEvent["key"];
}function useKeyPress(options: UseKeyPressOptions): boolean;Options
targetKey: KeyboardEvent["key"]
A predefined key value (i.e, Escape, Enter, Backspace, etc) to watch the keydown and keyup event on.