remixed v0
This commit is contained in:
17
app/features/keypad/hooks/use-key-press.ts
Normal file
17
app/features/keypad/hooks/use-key-press.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useCallback, useEffect } from "react";
|
||||
|
||||
export default function useKeyPress(onKeyPress: (key: string) => void) {
|
||||
const onKeyDown = useCallback(
|
||||
({ key }: KeyboardEvent) => {
|
||||
onKeyPress(key);
|
||||
},
|
||||
[onKeyPress],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [onKeyDown]);
|
||||
}
|
Reference in New Issue
Block a user