mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 03:03:37 +02:00
Refactor desktop app into separate client and proxy apps
This commit is contained in:
16
apps/yaak-client/hooks/useKeyboardEvent.ts
Normal file
16
apps/yaak-client/hooks/useKeyboardEvent.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useKeyboardEvent(
|
||||
event: 'keyup' | 'keydown',
|
||||
key: KeyboardEvent['key'],
|
||||
cb: () => void,
|
||||
) {
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Don't have `cb` as a dep for caller convenience
|
||||
useEffect(() => {
|
||||
const fn = (e: KeyboardEvent) => {
|
||||
if (e.key === key) cb();
|
||||
};
|
||||
document.addEventListener(event, fn);
|
||||
return () => document.removeEventListener(event, fn);
|
||||
}, [event]);
|
||||
}
|
||||
Reference in New Issue
Block a user