35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "Portal", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return Portal;
|
|
}
|
|
});
|
|
const _react = require("react");
|
|
const _reactdom = require("react-dom");
|
|
const Portal = (param)=>{
|
|
let { children, type } = param;
|
|
const [portalNode, setPortalNode] = (0, _react.useState)(null);
|
|
(0, _react.useEffect)(()=>{
|
|
const element = document.createElement(type);
|
|
document.body.appendChild(element);
|
|
setPortalNode(element);
|
|
return ()=>{
|
|
document.body.removeChild(element);
|
|
};
|
|
}, [
|
|
type
|
|
]);
|
|
return portalNode ? /*#__PURE__*/ (0, _reactdom.createPortal)(children, portalNode) : null;
|
|
};
|
|
|
|
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
Object.assign(exports.default, exports);
|
|
module.exports = exports.default;
|
|
}
|
|
|
|
//# sourceMappingURL=index.js.map
|