"use strict";

exports.__esModule = true;
exports.useElementOnScreen = void 0;

var _react = require("react");

const useElementOnScreen = options => {
  const containerRef = (0, _react.useRef)(null);
  const [isVisible, setIsVisible] = (0, _react.useState)(false);

  const callbackFunction = entries => {
    const [entry] = entries;
    setIsVisible(entry.isIntersecting);
  };

  (0, _react.useEffect)(() => {
    const observer = new IntersectionObserver(callbackFunction, options);
    if (containerRef.current) observer.observe(containerRef.current);
    return () => {
      if (containerRef.current) observer.unobserve(containerRef.current);
    };
  }, [containerRef, options]);
  return {
    containerRef,
    isVisible
  };
};

exports.useElementOnScreen = useElementOnScreen;