@fluentui/react
Version:
Reusable React components for building web experiences.
33 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LayerHost = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var react_hooks_1 = require("@fluentui/react-hooks");
var Utilities_1 = require("../../Utilities");
var Layer_notification_1 = require("./Layer.notification");
var LayerHost = function (props) {
var className = props.className;
var layerHostId = React.useState(function () { return Utilities_1.getId(); })[0];
var _a = props.id, hostId = _a === void 0 ? layerHostId : _a;
var layerHostRef = React.useRef({
hostId: hostId,
rootRef: React.useRef(null),
notifyLayersChanged: function () {
// Nothing, since the default implementation of Layer Host does not need to react to layer changes.
},
});
React.useImperativeHandle(props.componentRef, function () { return layerHostRef.current; });
React.useEffect(function () {
Layer_notification_1.registerLayerHost(hostId, layerHostRef.current);
Layer_notification_1.notifyHostChanged(hostId);
// eslint-disable-next-line react-hooks/exhaustive-deps -- should only run on first render
}, []);
react_hooks_1.useUnmount(function () {
Layer_notification_1.unregisterLayerHost(hostId, layerHostRef.current);
Layer_notification_1.notifyHostChanged(hostId);
});
return React.createElement("div", tslib_1.__assign({}, props, { className: Utilities_1.css('ms-LayerHost', className), ref: layerHostRef.current.rootRef }));
};
exports.LayerHost = LayerHost;
//# sourceMappingURL=LayerHost.js.map