From 6a1f9d9348bc1ac1a3dfba1ff4af44a70ef99a7e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 23 Oct 2024 08:15:09 +0400 Subject: [PATCH] Editor: Use plugin context hook in 'PluginPreviewMenuItem' --- packages/editor/README.md | 4 +-- .../plugin-preview-menu-item/index.js | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/editor/README.md b/packages/editor/README.md index 2acb98ef13642c..bcd1727e046d07 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -878,9 +878,9 @@ function onPreviewClick() { } const ExternalPreviewMenuItem = () => ( - + { __( 'Preview in new tab' ) } - + ); registerPlugin( 'external-preview-menu-item', { render: ExternalPreviewMenuItem, diff --git a/packages/editor/src/components/plugin-preview-menu-item/index.js b/packages/editor/src/components/plugin-preview-menu-item/index.js index 422248e17b88e1..8038da04595aae 100644 --- a/packages/editor/src/components/plugin-preview-menu-item/index.js +++ b/packages/editor/src/components/plugin-preview-menu-item/index.js @@ -1,9 +1,8 @@ /** * WordPress dependencies */ -import { compose } from '@wordpress/compose'; import { MenuItem } from '@wordpress/components'; -import { withPluginContext } from '@wordpress/plugins'; +import { usePluginContext } from '@wordpress/plugins'; import { ActionItem } from '@wordpress/interface'; /** @@ -27,12 +26,12 @@ import { ActionItem } from '@wordpress/interface'; * } * * const ExternalPreviewMenuItem = () => ( - * * { __( 'Preview in new tab' ) } - * + * * ); * registerPlugin( 'external-preview-menu-item', { * render: ExternalPreviewMenuItem, @@ -41,12 +40,14 @@ import { ActionItem } from '@wordpress/interface'; * * @return {Component} The rendered menu item component. */ -export default compose( - withPluginContext( ( context, ownProps ) => { - return { - as: ownProps.as ?? MenuItem, - icon: ownProps.icon || context.icon, - name: 'core/plugin-preview-menu', - }; - } ) -)( ActionItem ); +export default function PluginPreviewMenuItem( props ) { + const context = usePluginContext(); + return ( + + ); +}