Skip to content

Commit

Permalink
Update RoomHeader.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Averyberryman authored Oct 20, 2023
1 parent b9e3d7a commit 4b255f8
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/components/RoomHeader/RoomHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ import alien from "../../assets/alien.png";

export default function RoomHeader() {
const [timer, setTimer] = useState(0);
const [isActive, setIsActive] = useState(true);

useEffect(() => {
let interval;

if (isActive) {
interval = setInterval(() => {
setTimer((prevTimer) => prevTimer + 0.01);
}, 10);
} else {
clearInterval(interval);
}
const interval = setInterval(() => {
setTimer((prevTimer) => prevTimer + 0.01);
}, 10);

return () => clearInterval(interval);
}, [isActive]);
}, []);

const minutes = Math.floor(timer / 60);
const seconds = timer % 60;
Expand All @@ -34,3 +27,4 @@ export default function RoomHeader() {
);
}


0 comments on commit 4b255f8

Please sign in to comment.