@fluentui/react
Version:
Reusable React components for building web experiences.
30 lines • 1.76 kB
JavaScript
define(["require", "exports", "tslib", "react", "@fluentui/react-hooks", "../../Utilities", "./Layer.notification"], function (require, exports, tslib_1, React, react_hooks_1, Utilities_1, Layer_notification_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LayerHost = void 0;
var LayerHost = function (props) {
var className = props.className;
var layerHostId = React.useState(function () { return (0, 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 () {
(0, Layer_notification_1.registerLayerHost)(hostId, layerHostRef.current);
(0, Layer_notification_1.notifyHostChanged)(hostId);
// eslint-disable-next-line react-hooks/exhaustive-deps -- should only run on first render
}, []);
(0, react_hooks_1.useUnmount)(function () {
(0, Layer_notification_1.unregisterLayerHost)(hostId, layerHostRef.current);
(0, Layer_notification_1.notifyHostChanged)(hostId);
});
return React.createElement("div", tslib_1.__assign({}, props, { className: (0, Utilities_1.css)('ms-LayerHost', className), ref: layerHostRef.current.rootRef }));
};
exports.LayerHost = LayerHost;
});
//# sourceMappingURL=LayerHost.js.map