/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/core-data/src/entity-provider.js
47 строк
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { useContext, useMemo } from '@wordpress/element'; import { EntityContext } from './entity-context'; /** * 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 {number} [props.revisionId] Optional revision ID. When set, * `useEntityProp` reads from the * revision record instead of the * current entity. * @param {*} props.children The children to wrap. * * @return {Object} The provided children, wrapped with * the entity's context provider. */ export default function EntityProvider( { kind, type: name, id, revisionId, children, } ) { const parent = useContext( EntityContext ); const childContext = useMemo( () => ( { ...parent, ...( kind && { [ kind ]: { ...parent?.[ kind ], [ name ]: id, }, } ), ...( revisionId !== undefined && { revisionId } ), } ), [ parent, kind, name, id, revisionId ] ); return ( <EntityContext.Provider value={ childContext }> { children } </EntityContext.Provider> ); }