mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-12 19:02:53 +08:00
refactor code
This commit is contained in:
parent
01ab331790
commit
b1e9824e20
@ -1,15 +1,15 @@
|
||||
import React from "react";
|
||||
|
||||
const useKeyPress = (targetKey) => {
|
||||
const useKeyPress = (targetKey: string) => {
|
||||
const [keyPressed, setKeyPressed] = React.useState(false);
|
||||
|
||||
function downHandler({ key }) {
|
||||
if (key === targetKey) setKeyPressed(true);
|
||||
}
|
||||
const upHandler = ({ key }) => {
|
||||
if (key === targetKey) setKeyPressed(false);
|
||||
};
|
||||
React.useEffect(() => {
|
||||
function downHandler({ key }) {
|
||||
if (key === targetKey) setKeyPressed(true);
|
||||
}
|
||||
const upHandler = ({ key }) => {
|
||||
if (key === targetKey) setKeyPressed(false);
|
||||
};
|
||||
window.addEventListener("keydown", downHandler);
|
||||
window.addEventListener("keyup", upHandler);
|
||||
|
||||
@ -17,7 +17,8 @@ const useKeyPress = (targetKey) => {
|
||||
window.removeEventListener("keydown", downHandler);
|
||||
window.removeEventListener("keyup", upHandler);
|
||||
};
|
||||
}, []);
|
||||
}, [targetKey]);
|
||||
|
||||
return keyPressed;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user