import { useEffect } from "react"; /** Fades in every `.reveal` element as it scrolls into view, including ones added after navigation. */ export function useScrollReveal() { useEffect(() => { document.documentElement.classList.add("reveal-ready"); const io = new IntersectionObserver( (entries) => entries.forEach((e) => { if (e.isIntersecting) { e.target.classList.add("is-visible"); io.unobserve(e.target); } }), { threshold: 0.12, rootMargin: "0px 0px -40px 0px" }, ); const scan = () => document.querySelectorAll(".reveal:not(.is-visible)").forEach((el) => io.observe(el)); scan(); const mo = new MutationObserver(scan); mo.observe(document.body, { childList: true, subtree: true }); return () => { io.disconnect(); mo.disconnect(); }; }, []); }