Files
my-links/inertia/hooks/use_shortcut.tsx
2024-06-02 23:59:57 +02:00

20 lines
580 B
TypeScript

import KEYS from '#constants/keys';
import { useHotkeys } from 'react-hotkeys-hook';
import useGlobalHotkeys from '~/hooks/use_global_hotkeys';
type ShortcutOptions = { ignoreGlobalHotkeysStatus?: boolean };
export default function useShortcut(
key: keyof typeof KEYS,
cb: () => void,
options: ShortcutOptions = {
ignoreGlobalHotkeysStatus: false,
}
) {
const { globalHotkeysEnabled } = useGlobalHotkeys();
return useHotkeys(KEYS[key], cb, {
enabled: !options.ignoreGlobalHotkeysStatus ? globalHotkeysEnabled : true,
enableOnFormTags: ['INPUT'],
});
}