Files
supabase/apps/studio/hooks/ui/useHotKey.ts
Ali Waseem 8b2dcaa352 Revert "Fix queue operations stale state + refactor to reuse existing… (#42290)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Reverting commit due to high error rates
2026-01-29 16:26:54 +00:00

26 lines
604 B
TypeScript

import { useEffect } from 'react'
export function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
dependencies: any[] = [],
options?: { enabled?: boolean }
): void {
const enabled = options?.enabled ?? true
useEffect(() => {
if (!enabled) return
function handler(e: KeyboardEvent) {
if ((e.metaKey || e.ctrlKey) && e.key === key && !e.altKey && !e.shiftKey) {
callback(e)
}
}
window.addEventListener('keydown', handler)
return () => {
window.removeEventListener('keydown', handler)
}
}, [key, enabled, ...dependencies])
}