mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-13 19:30:29 +02:00
Split codebase (#455)
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,
|
||||
) {
|
||||
// oxlint-disable-next-line react-hooks/exhaustive-deps -- 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