create-expo-cljs-app
Version:
Create a react native application with Expo and Shadow-CLJS!
40 lines (35 loc) • 1.08 kB
JavaScript
/**
* Copyright (c) Nicolas Gallagher.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
import * as React from 'react';
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
import ReactDOM from 'react-dom';
function ModalPortal(props) {
var children = props.children;
var elementRef = React.useRef(null);
if (canUseDOM && !elementRef.current) {
var element = document.createElement('div');
if (element && document.body) {
document.body.appendChild(element);
elementRef.current = element;
}
}
React.useEffect(function () {
if (canUseDOM) {
return function () {
if (document.body && elementRef.current) {
document.body.removeChild(elementRef.current);
elementRef.current = null;
}
};
}
}, []);
return elementRef.current && canUseDOM ? /*#__PURE__*/ReactDOM.createPortal(children, elementRef.current) : null;
}
export default ModalPortal;