UNPKG

@wordpress/components

Version:
70 lines (59 loc) 2.28 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Fill; var _element = require("@wordpress/element"); var _context = _interopRequireDefault(require("./context")); var _useSlot = _interopRequireDefault(require("./use-slot")); // @ts-nocheck /** * WordPress dependencies */ /** * Internal dependencies */ function Fill(_ref) { let { name, children } = _ref; const { registerFill, unregisterFill } = (0, _element.useContext)(_context.default); const slot = (0, _useSlot.default)(name); const ref = (0, _element.useRef)({ name, children }); (0, _element.useLayoutEffect)(() => { const refValue = ref.current; registerFill(name, refValue); return () => unregisterFill(name, refValue); // Ignore reason: the useLayoutEffects here are written to fire at specific times, and introducing new dependencies could cause unexpected changes in behavior. // We'll leave them as-is until a more detailed investigation/refactor can be performed. // eslint-disable-next-line react-hooks/exhaustive-deps }, []); (0, _element.useLayoutEffect)(() => { ref.current.children = children; if (slot) { slot.forceUpdate(); } // Ignore reason: the useLayoutEffects here are written to fire at specific times, and introducing new dependencies could cause unexpected changes in behavior. // We'll leave them as-is until a more detailed investigation/refactor can be performed. // eslint-disable-next-line react-hooks/exhaustive-deps }, [children]); (0, _element.useLayoutEffect)(() => { if (name === ref.current.name) { // Ignore initial effect. return; } unregisterFill(ref.current.name, ref.current); ref.current.name = name; registerFill(name, ref.current); // Ignore reason: the useLayoutEffects here are written to fire at specific times, and introducing new dependencies could cause unexpected changes in behavior. // We'll leave them as-is until a more detailed investigation/refactor can be performed. // eslint-disable-next-line react-hooks/exhaustive-deps }, [name]); return null; } //# sourceMappingURL=fill.js.map