Files
tolaria/src/hooks/useAppKeyboard.ts
2026-04-08 14:01:19 +02:00

21 lines
668 B
TypeScript

import { useEffect, useEffectEvent } from 'react'
import { handleAppKeyboardEvent } from './appKeyboardShortcuts'
import type { KeyboardActions } from './appKeyboardShortcuts'
export type { KeyboardActions } from './appKeyboardShortcuts'
export function useAppKeyboard(actions: KeyboardActions) {
const onKeyDown = useEffectEvent((event: KeyboardEvent) => {
handleAppKeyboardEvent(actions, event)
})
useEffect(() => {
const handleWindowKeyDown = (event: KeyboardEvent) => {
onKeyDown(event)
}
window.addEventListener('keydown', handleWindowKeyDown)
return () => window.removeEventListener('keydown', handleWindowKeyDown)
}, [])
}