function useHotkey<T>(
hotkey,
callback,
options?): void;Defined in: useHotkey.ts:85
React hook for registering a hotkey: a chord such as 'Mod+S', a sequence such as ['G', 'G'], or an app hotkey from defineAppHotkeys.
Uses the singleton HotkeyManager for efficient event handling. The callback and options sync on every render, so callbacks that reference React state always see the latest values. enabled: false keeps the registration (visible in devtools) and only suppresses firing.
Chords accept requireReset; sequences accept timeout. A one-step sequence registers as its chord. An app hotkey uses its effective hotkey from HotkeysProvider (including the user's custom hotkey) and its declared meta and options, and registers nothing while unbound.
Options merge in this order: provider defaults, app hotkey declaration, call-site options.
T extends AppHotkey<string, HotkeyChord | HotkeySequence | null>
T
A chord string, RawHotkey object, sequence, or app hotkey
HotkeyCallback
The function to call when the hotkey is pressed
Options for the hotkey behavior
void
function Editor() {
const [count, setCount] = useState(0)
useHotkey('Mod+S', () => save(count))
useHotkey(['G', 'G'], () => scrollToTop(), { timeout: 500 })
useHotkey('Escape', () => close(), { enabled: isOpen })
}function Toolbar() {
const hotkeys = useAppHotkeys()
useHotkey(hotkeys['doc.save'], () => save())
}function useHotkey<T>(
hotkey,
callback,
options?): void;Defined in: useHotkey.ts:90
React hook for registering a hotkey: a chord such as 'Mod+S', a sequence such as ['G', 'G'], or an app hotkey from defineAppHotkeys.
Uses the singleton HotkeyManager for efficient event handling. The callback and options sync on every render, so callbacks that reference React state always see the latest values. enabled: false keeps the registration (visible in devtools) and only suppresses firing.
Chords accept requireReset; sequences accept timeout. A one-step sequence registers as its chord. An app hotkey uses its effective hotkey from HotkeysProvider (including the user's custom hotkey) and its declared meta and options, and registers nothing while unbound.
Options merge in this order: provider defaults, app hotkey declaration, call-site options.
T extends RegisterableHotkey
T
A chord string, RawHotkey object, sequence, or app hotkey
HotkeyCallback
The function to call when the hotkey is pressed
AdapterOptionsFor<T, UseHotkeyTarget>
Options for the hotkey behavior
void
function Editor() {
const [count, setCount] = useState(0)
useHotkey('Mod+S', () => save(count))
useHotkey(['G', 'G'], () => scrollToTop(), { timeout: 500 })
useHotkey('Escape', () => close(), { enabled: isOpen })
}function Toolbar() {
const hotkeys = useAppHotkeys()
useHotkey(hotkeys['doc.save'], () => save())
}