refactor: stats moved to sepetate component

This commit is contained in:
2025-08-01 13:28:42 +05:30
parent 7bc0be6e1d
commit 45358502f8
2 changed files with 25 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
import { useEffect, useState } from "react";
import { Stats } from "@react-three/drei";
import { detectModifierKeys } from "../../../utils/shortcutkeys/detectModifierKeys";
export default function StatsHelper() {
const [visible, setVisible] = useState(false);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
const keyCombination = detectModifierKeys(event);
if (keyCombination === "F1") {
event.preventDefault();
setVisible(prev => !prev);
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, []);
return visible ? <Stats className="stats" /> : null;
}