UNPKG

@wordpress/core-data

Version:
49 lines (46 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = EntityProvider; var _element = require("@wordpress/element"); var _entityContext = require("./entity-context"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Context provider component for providing * an entity for a specific entity. * * @param {Object} props The component's props. * @param {string} props.kind The entity kind. * @param {string} props.type The entity name. * @param {number} props.id The entity ID. * @param {*} props.children The children to wrap. * * @return {Object} The provided children, wrapped with * the entity's context provider. */function EntityProvider({ kind, type: name, id, children }) { const parent = (0, _element.useContext)(_entityContext.EntityContext); const childContext = (0, _element.useMemo)(() => ({ ...parent, [kind]: { ...parent?.[kind], [name]: id } }), [parent, kind, name, id]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_entityContext.EntityContext.Provider, { value: childContext, children: children }); } //# sourceMappingURL=entity-provider.js.map