/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/plugins/src/components/plugin-context/index.tsx
61 строка
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { createContext, useContext } from '@wordpress/element'; import { createHigherOrderComponent } from '@wordpress/compose'; import deprecated from '@wordpress/deprecated'; import type { WPPlugin } from '../../api'; export interface PluginContext { name: null | WPPlugin[ 'name' ]; icon: null | WPPlugin[ 'icon' ]; } const Context = createContext< PluginContext >( { name: null, icon: null, } ); Context.displayName = 'PluginContext'; export const PluginContextProvider = Context.Provider; /** * A hook that returns the plugin context. * * @return {PluginContext} Plugin context */ export function usePluginContext() { return useContext( Context ); } /** * A Higher Order Component used to inject Plugin context to the * wrapped component. * * @deprecated 6.8.0 Use `usePluginContext` hook instead. * * @param mapContextToProps Function called on every context change, * expected to return object of props to * merge with the component's own props. * * @return {Component} Enhanced component with injected context as props. */ export const withPluginContext = ( mapContextToProps: < T >( context: PluginContext, props: T ) => T & PluginContext ) => createHigherOrderComponent( ( OriginalComponent ) => { deprecated( 'wp.plugins.withPluginContext', { since: '6.8.0', alternative: 'wp.plugins.usePluginContext', } ); return ( props ) => ( <Context.Consumer> { ( context ) => ( <OriginalComponent { ...props } { ...mapContextToProps( context, props ) } /> ) } </Context.Consumer> ); }, 'withPluginContext' );