Returns a callback that triggers only when specific keys are pressed.
The HTML element type.
An array of key values to listen for.
The function to call when a matching key is pressed.
A KeyboardEvent handler.
KeyboardEvent
This hook is useful for handling keyboard shortcuts or specific key interactions. It checks event.key against the provided list of keys.
event.key
const onKeyDown = useKeyCallback(["Enter", " "], (e) => { submit();});return <div onKeyDown={onKeyDown} />; Copy
const onKeyDown = useKeyCallback(["Enter", " "], (e) => { submit();});return <div onKeyDown={onKeyDown} />;
Returns a callback that triggers only when specific keys are pressed.