From 2845fb9e60a3760a3a6b702bf2aa11d7a82315db Mon Sep 17 00:00:00 2001 From: Weile Date: Sun, 15 Sep 2024 16:17:25 -0400 Subject: [PATCH] (bug) fix bug --- pages/index.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/index.jsx b/pages/index.jsx index 3c3b8af..b114721 100644 --- a/pages/index.jsx +++ b/pages/index.jsx @@ -164,9 +164,12 @@ function ProjectCard({ json, basePath }) { ); } +import React, { useEffect } from "react"; + function Factbox({ fact, closer }) { - if (typeof window !== "undefined") { + useEffect(() => { const elements = document.querySelectorAll(".number"); + const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { @@ -190,10 +193,12 @@ function Factbox({ fact, closer }) { } }); }); + elements.forEach((element) => { observer.observe(element); }); - } + }, []); // Empty dependency array means this effect runs once after the initial render + return (