70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
// Metro module 4061 (f4062).
|
|
import * as _Module19 from "react";
|
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
import { usePortal } from "./Module4062";
|
|
import { nanoid } from "./Module1489";
|
|
const memo2 = _Module19.memo;
|
|
const r19 = memo2(({ name, hostName, handleOnMount, handleOnUnmount, handleOnUpdate, children }) => {
|
|
let ref, ref2, ref3;
|
|
ref = void 0;
|
|
ref2 = void 0;
|
|
ref3 = void 0;
|
|
const portal = usePortal(hostName);
|
|
const { addPortal, removePortal } = portal;
|
|
const memo = useMemo(() => {
|
|
let r4 = name;
|
|
if (!name) {
|
|
r4 = nanoid();
|
|
}
|
|
return r4;
|
|
}, [name]);
|
|
ref = useRef();
|
|
ref2 = useRef();
|
|
ref3 = useRef();
|
|
ref.current = useCallback(() => {
|
|
if (handleOnMount) {
|
|
handleOnMount(() => addPortal(memo, children));
|
|
} else {
|
|
addPortal(memo, children);
|
|
}
|
|
}, [handleOnMount, addPortal]);
|
|
ref2.current = useCallback(() => {
|
|
if (handleOnUnmount) {
|
|
handleOnUnmount(() => removePortal(memo));
|
|
} else {
|
|
removePortal(memo);
|
|
}
|
|
}, [handleOnUnmount, removePortal]);
|
|
ref3.current = useCallback(() => {
|
|
if (handleOnUpdate) {
|
|
handleOnUpdate(() => addPortal(memo, children));
|
|
} else {
|
|
addPortal(memo, children);
|
|
}
|
|
}, [handleOnUpdate, addPortal, children]);
|
|
useEffect(() => {
|
|
const current = ref.current;
|
|
if (current != null) {
|
|
current.call(ref);
|
|
}
|
|
return () => {
|
|
const current = ref2.current;
|
|
if (current != null) {
|
|
current.call(ref2);
|
|
}
|
|
ref.current = void 0;
|
|
ref2.current = void 0;
|
|
ref3.current = void 0;
|
|
};
|
|
}, []);
|
|
useEffect(() => {
|
|
const current = ref3.current;
|
|
if (current != null) {
|
|
current.call(ref3);
|
|
}
|
|
}, [children]);
|
|
return null;
|
|
});
|
|
r19.displayName = "Portal";
|
|
export { r19 as Portal };
|