useIsShortcutEnabled.ts20 lines · main
1import type { ShortcutId } from './registry'
2import { useShortcutPreferences } from './state'
3
4/**
5 * Reactive check for whether a shortcut is currently enabled for the user.
6 *
7 * Subscribes the calling component to the shortcut preferences query so it
8 * re-renders when the user toggles this shortcut in Account → Preferences.
9 *
10 * For one-off, non-reactive checks outside render (event handlers, module-level
11 * code), use the plain `isShortcutEnabled(id)` function from `./state` instead.
12 *
13 * @example
14 * const isEnabled = useIsShortcutEnabled(SHORTCUT_IDS.AI_ASSISTANT_TOGGLE)
15 * return <Tooltip>{isEnabled && <KeyboardShortcut keys={['Meta', 'I']} />}</Tooltip>
16 */
17export function useIsShortcutEnabled(id: ShortcutId): boolean {
18 const { disabled } = useShortcutPreferences()
19 return !disabled[id]
20}