mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-10 00:51:34 +11:00
18 lines
418 B
TypeScript
18 lines
418 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);
|
|
};
|
|
}, [callback, targetKey]);
|
|
};
|