@mirawision/reactive-hooks
Version:
A comprehensive collection of 50+ React hooks for state management, UI interactions, device APIs, async operations, drag & drop, audio/speech, and more. Full TypeScript support with SSR safety.
16 lines (15 loc) • 728 B
TypeScript
import { RefObject } from 'react';
export type KeyMatch = string | ((e: KeyboardEvent) => boolean);
export interface UseKeyPressOptions {
target?: Window | Document | HTMLElement | RefObject<Element>;
event?: 'keydown' | 'keyup' | 'keypress';
preventDefault?: boolean;
stopPropagation?: boolean;
}
/**
* A hook for handling keyboard events with flexible key matching.
* @param keys Single key or array of keys to match (string or predicate function)
* @param handler Callback function to execute when key matches
* @param opts Configuration options for event handling
*/
export declare function useKeyPress(keys: KeyMatch | KeyMatch[], handler: (e: KeyboardEvent) => void, opts?: UseKeyPressOptions): void;