From 5a10642709a6aac40e380dc16c42656fb4a7b4ac Mon Sep 17 00:00:00 2001 From: Gabriel Cozma Date: Tue, 11 Jun 2024 21:47:50 +0300 Subject: [PATCH] fix: no useEffect --- src/pages/index.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index d7cfb96..49f45f1 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -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; @@ -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() {