import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import * as React from '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 = _slicedToArray(_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];
};

export default useMutationObserverRef;