%PDF- %PDF-
Direktori : /var/www/html/src/Components/ |
Current File : //var/www/html/src/Components/useInView.js |
import { useEffect, useRef, useState } from "react"; export const useInView = (ref, options) => { const [isIntersecting, setIsIntersecting] = useState(false); const observerRef = useRef(null); useEffect(() => { observerRef.current = new IntersectionObserver(([entry]) => { setIsIntersecting(entry.isIntersecting); }, options); }, []); useEffect(() => { observerRef.current.observe(ref.current); return () => { observerRef.current.disconnect(); }; }, [ref, options]); return isIntersecting; };