"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"));
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function Fill({
  name,
  children
}) {
  const registry = (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;
    refValue.name = name;
    registry.registerFill(name, refValue);
    return () => registry.unregisterFill(name, refValue);
  }, [registry, name]);
  (0, _element.useLayoutEffect)(() => {
    ref.current.children = children;
    if (slot) {
      slot.rerender();
    }
  }, [slot, children]);
  return null;
}
//# sourceMappingURL=fill.js.map