import { useCallback as l, useEffect as f } from "react";
const v = (s, c, h = {}) => {
  const { distance: i = 10, loadFirst: t = !1 } = h, o = l(
    (u) => {
      if (!s)
        return;
      s.scrollHeight - s.clientHeight - s.scrollTop < i && c();
    },
    [c, s, i]
  );
  f(() => {
    t && c();
  }, [t]), f(() => (s == null || s.addEventListener("scroll", o), () => {
    s == null || s.removeEventListener("scroll", o);
  }), [o, s]);
};
export {
  v as useInfiniteScroll
};
