refactor: create shortcut hook that with default config

This commit is contained in:
Sonny
2024-05-16 22:03:00 +02:00
committed by Sonny
parent 57ed2c5e94
commit 18b2eb2c5a
6 changed files with 82 additions and 62 deletions

View File

@@ -0,0 +1,11 @@
import KEYS from '#constants/keys';
import { useHotkeys } from 'react-hotkeys-hook';
import useGlobalHotkeys from '~/hooks/use_global_hotkeys';
export default function useShortcut(key: keyof typeof KEYS, cb: () => void) {
const { globalHotkeysEnabled } = useGlobalHotkeys();
return useHotkeys(KEYS[key], cb, {
enabled: globalHotkeysEnabled,
enableOnFormTags: ['INPUT'],
});
}