45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
// Metro module 4062 (f4063).
|
|
import { useCallback, useContext } from "react";
|
|
import * as _Module4063 from "./Module4063";
|
|
import { ACTIONS } from "./Module4064";
|
|
export const usePortal = function(r4 = "root") {
|
|
const hostName = r4;
|
|
const context = useContext(_Module4063.PortalDispatchContext);
|
|
if (context === null) {
|
|
throw new Error("'PortalDispatchContext' cannot be null, please add 'PortalProvider' to the root component.");
|
|
}
|
|
const callback = useCallback(() => {
|
|
context({
|
|
type: ACTIONS.REGISTER_HOST,
|
|
hostName
|
|
});
|
|
}, []);
|
|
const callback2 = useCallback(() => {
|
|
context({
|
|
type: ACTIONS.DEREGISTER_HOST,
|
|
hostName
|
|
});
|
|
}, []);
|
|
const callback3 = useCallback((a0, a1) => {
|
|
context({
|
|
type: ACTIONS.ADD_UPDATE_PORTAL,
|
|
hostName,
|
|
portalName: a0,
|
|
node: a1
|
|
});
|
|
}, []);
|
|
return {
|
|
registerHost: callback,
|
|
deregisterHost: callback2,
|
|
addPortal: callback3,
|
|
updatePortal: callback3,
|
|
removePortal: useCallback((a0) => {
|
|
context({
|
|
type: ACTIONS.REMOVE_PORTAL,
|
|
hostName,
|
|
portalName: a0
|
|
});
|
|
}, [])
|
|
};
|
|
};
|