"use client"; import { useEffect, useRef, useState } from "react"; export function useInView(threshold = 0.4) { const ref = useRef(null); const [inView, setInView] = useState(false); useEffect(() => { const node = ref.current; if (!node) return; const obs = new IntersectionObserver( ([entry]) => setInView(entry.isIntersecting), { threshold }, ); obs.observe(node); return () => obs.disconnect(); }, [threshold]); return { ref, inView }; }