import { useEffect, useRef } from "react";
/**
 * Listen for the specified element to scroll to the bottom
 */ export function useEndReached(sentinelRef, onEndReached) {
    const observer = useRef();
    const cb = useRef(onEndReached);
    cb.current = onEndReached;
    useEffect(()=>{
        const options = {
            root: null,
            rootMargin: "0px",
            threshold: 0
        };
        const handleObserver = (entries)=>{
            entries.forEach((entry)=>{
                if (entry.isIntersecting) {
                    cb.current?.();
                }
            });
        };
        observer.current = new IntersectionObserver(handleObserver, options);
        return ()=>{
            observer.current?.disconnect();
        };
    }, []);
    useEffect(()=>{
        observer.current?.observe(sentinelRef.current);
    }, []);
}

//# sourceMappingURL=useEndReached.js.map