text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  var React = require('react');
  var utils = require('@reach/utils');
  var reactDom = require('react-dom');
  
  /**
   * Welcome to @reach/portal!
   *
   * Creates and appends a DOM node to the end of `document.body` and renders a
   * React tree into it. Useful for rendering a natural React element hierarchy
   * with a different DOM hierarchy to prevent parent styles from clipping or
   * hiding content (for popovers, dropdowns, and modals).
   *
   * @see Docs   https://reach.tech/portal
   * @see Source https://github.com/reach/reach-ui/tree/main/packages/portal
   * @see React  https://reactjs.org/docs/portals.html
   */
  /**
   * Portal
   *
   * @see Docs https://reach.tech/portal#portal
   */
  
  var Portal = function Portal(_ref) {
    var children = _ref.children,
        _ref$type = _ref.type,
        type = _ref$type === void 0 ? "reach-portal" : _ref$type;
    var mountNode = React.useRef(null);
    var portalNode = React.useRef(null);
    var forceUpdate = utils.useForceUpdate();
    utils.useIsomorphicLayoutEffect(function () {
      // This ref may be null when a hot-loader replaces components on the page
      if (!mountNode.current) return; // It's possible that the content of the portal has, itself, been portaled.
      // In that case, it's important to append to the correct document element.
  
      var ownerDocument = mountNode.current.ownerDocument;
      portalNode.current = ownerDocument == null ? void 0 : ownerDocument.createElement(type);
      ownerDocument.body.appendChild(portalNode.current);
      forceUpdate();
      return function () {
        if (portalNode.current && portalNode.current.ownerDocument) {
          portalNode.current.ownerDocument.body.removeChild(portalNode.current);
        }
      };
    }, [type, forceUpdate]);
    return portalNode.current ? /*#__PURE__*/reactDom.createPortal(children, portalNode.current) : /*#__PURE__*/React.createElement("span", {
      ref: mountNode
    });
  };
  
  exports.Portal = Portal;
  exports.default = Portal;
  