"use strict";

exports.__esModule = true;
exports.useIntersectionObserver = useIntersectionObserver;
var _react = require("react");
function useIntersectionObserver(callback, threshold = 0.9) {
  const elementRef = (0, _react.useRef)(null);
  const [intersectionObserver] = (0, _react.useState)(() => {
    // in jsdom, IntersectionObserver is not implemeted
    if (typeof IntersectionObserver === 'undefined') {
      return null;
    }
    return new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting) {
        callback();
        intersectionObserver == null || intersectionObserver.disconnect();
      }
    }, {
      threshold
    });
  });
  (0, _react.useEffect)(() => {
    const element = elementRef.current;
    if (!element || !intersectionObserver) {
      return;
    }
    intersectionObserver.observe(element);
    return () => {
      intersectionObserver.disconnect();
    };
  }, []);
  return {
    elementRef
  };
}
//# sourceMappingURL=useIntersectionObserver.js.map