mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 13:19:09 +03:00
## 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
26 lines
604 B
TypeScript
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])
|
|
}
|