UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

40 lines (31 loc) 1.33 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var React = require('react'); var React__default = _interopDefault(React); var reactDom = require('react-dom'); 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 _useState = React.useState(), forceUpdate = _useState[1]; React.useLayoutEffect(function () { // It's possible that the content we are 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.createElement(type); ownerDocument.body.appendChild(portalNode.current); forceUpdate({}); return function () { portalNode.current.ownerDocument.body.removeChild(portalNode.current); }; }, [type]); return portalNode.current ? reactDom.createPortal(children, portalNode.current) : React__default.createElement("div", { ref: mountNode }); } Portal.displayName = "Portal"; exports.default = Portal;