Skip to content

Commit

Permalink
fix: no useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
GabsEdits committed Jun 11, 2024
1 parent 5867ee5 commit 5a10642
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ export default function Home() {
};

useEffect(() => {
useEffect(() => {
const hoverElement = document.querySelector("h1");
const originalColor = "var(--color-text)";
const hoverElement = document.querySelector("h1");
const originalColor = "var(--color-text)";

if (hoverElement) {
if (hoverElement) {
hoverElement.addEventListener("mouseenter", function () {
const randomColor = getRandomColor();
hoverElement.style.color = randomColor;
Expand All @@ -208,16 +207,15 @@ export default function Home() {

return () => {
hoverElement.removeEventListener("mouseenter", function () {
const randomColor = getRandomColor();
hoverElement.style.color = randomColor;
const randomColor = getRandomColor();
hoverElement.style.color = randomColor;
});

hoverElement.removeEventListener("mouseleave", function () {
hoverElement.style.color = originalColor;
hoverElement.style.color = originalColor;
});
};
}
}, []);
}
}, []);

function getRandomColor() {
Expand Down

0 comments on commit 5a10642

Please sign in to comment.