UNPKG

@wordpress/components

Version:
30 lines (29 loc) 808 B
/** * WordPress dependencies */ import { useContext, useLayoutEffect, useRef } from '@wordpress/element'; /** * Internal dependencies */ import SlotFillContext from './context'; export default function Fill({ name, children }) { const registry = useContext(SlotFillContext); const instanceRef = useRef({}); const childrenRef = useRef(children); useLayoutEffect(() => { childrenRef.current = children; }, [children]); useLayoutEffect(() => { const instance = instanceRef.current; registry.registerFill(name, instance, childrenRef.current); return () => registry.unregisterFill(name, instance); }, [registry, name]); useLayoutEffect(() => { registry.updateFill(name, instanceRef.current, childrenRef.current); }); return null; } //# sourceMappingURL=fill.js.map