import { useEffect } from 'react';
/**
 * @example useItemIntersection(listRef,offset,() => { do_some_thing; });
 * @param containerRef The ref of the List.
 * @param offset  Index of the list item which needs to be observed.
 * @param cb Callback that needs to be fired on intersect
 * @param itemSelector Selector used to get the node list of items
 * @returns void.
 */
const useItemIntersection = (containerRef, offset, cb, itemSelector) => {
    useEffect(() => {
        if (!containerRef.current)
            return;
        let item = null;
        if (offset > 0) {
            const items = containerRef.current.querySelectorAll(itemSelector);
            if (items.length > offset) {
                item = items[offset];
            }
        }
        if (item) {
            const intersectionObserver = new IntersectionObserver((entries) => {
                if (entries[0].isIntersecting) {
                    cb();
                }
            }, {
                root: containerRef.current
            });
            intersectionObserver.observe(item);
            return () => {
                intersectionObserver.disconnect();
            };
        }
    }, [cb, containerRef.current, offset]);
};
export default useItemIntersection;
//# sourceMappingURL=useItemIntersection.js.map