"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var React = _interopRequireWildcard(require("react"));

var config = {
  attributes: true,
  characterData: true,
  childList: true,
  subtree: true
};

var useMutationObserverRef = function useMutationObserverRef(callback) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : config;

  var _React$useState = React.useState(null),
      _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
      target = _React$useState2[0],
      setTarget = _React$useState2[1];

  React.useEffect(function () {
    if (target) {
      var observer = new MutationObserver(callback);
      observer.observe(target, options);
      return function () {
        observer.disconnect();
      };
    }
  }, [target, callback, options]);
  return [target, setTarget];
};

var _default = useMutationObserverRef;
exports.default = _default;