mango-v4-ui/hooks/useCustomHotKeys.ts

23 lines
479 B
TypeScript
Raw Normal View History

2023-08-30 20:52:33 -07:00
import { HotKey } from '@components/settings/HotKeysSettings'
import { useHotkeys } from 'react-hotkeys-hook'
export const useCustomHotkeys = (
hotkeys: HotKey[],
handleHotkeyAction: (hotkey: HotKey) => void,
) => {
hotkeys.forEach((hotkey: HotKey) => {
const { keySequence } = hotkey
useHotkeys(
keySequence,
(event) => {
event.preventDefault()
handleHotkeyAction(hotkey)
},
{
keydown: true,
},
)
})
}