useKeyboardShortcut
HookBinds a keyboard shortcut with modifier key support (Ctrl, Meta, Shift, Alt).
npx arupui add use-keyboard-shortcut
Usage
use-keyboard-shortcut.tsx
import { useKeyboardShortcut } from "@/hooks/use-keyboard-shortcut"
function SearchDialog() {
const [open, setOpen] = useState(false)
useKeyboardShortcut(
{ key: "k", meta: true },
() => setOpen(true)
)
return open ? <CommandPalette /> : null
}Parameters
| Parameter | Type | Description |
|---|---|---|
options | { key, ctrl?, meta?, shift?, alt? } | Shortcut config |
callback | (event: KeyboardEvent) => void | Handler function |
options{ key, ctrl?, meta?, shift?, alt? }Shortcut config
callback(event: KeyboardEvent) => voidHandler function
Returns
void