import { useState, useEffect } from 'react';

const threshold = new Array(101).fill(1).map((value, index) => index / 100);
function useElementIntersectionRatio(el, parent) {
  const [entry, setEntry] = useState(null);
  useEffect(() => {
    if (!el.current) {
      return;
    }
    const observer = new IntersectionObserver(
      (entries) => {
        setEntry(entries[0] || null);
      },
      {
        threshold,
        root: (parent == null ? void 0 : parent.current) || document.body,
        rootMargin: "-32px 0px 0px 0px"
      }
    );
    observer.observe(el.current);
    return () => {
      observer.disconnect();
    };
  }, [el, parent]);
  return entry;
}

export { useElementIntersectionRatio as default };
