mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-10 17:11:34 +11:00
18 lines
399 B
TypeScript
18 lines
399 B
TypeScript
|
import { useEffect } from "react";
|
||
|
|
||
|
export const useOnKeyUp = (targetKey: string, callback: () => void) => {
|
||
|
useEffect(() => {
|
||
|
const downHandler = (evnt: KeyboardEvent) => {
|
||
|
if (evnt.key === targetKey) {
|
||
|
callback();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
window.addEventListener("keyup", downHandler);
|
||
|
|
||
|
return () => {
|
||
|
window.removeEventListener("keyup", downHandler);
|
||
|
};
|
||
|
}, []);
|
||
|
};
|