From 52d819ee3aa80ee66cfd58042b82a7dd074f69d0 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Tue, 1 Aug 2023 14:33:52 +0300 Subject: [PATCH 1/2] Editor: Use hooks instead of HoCs --- .../src/components/post-pingbacks/index.js | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/editor/src/components/post-pingbacks/index.js b/packages/editor/src/components/post-pingbacks/index.js index b2274075f1fe4c..582ad5661eb393 100644 --- a/packages/editor/src/components/post-pingbacks/index.js +++ b/packages/editor/src/components/post-pingbacks/index.js @@ -3,17 +3,23 @@ */ import { __ } from '@wordpress/i18n'; import { CheckboxControl } from '@wordpress/components'; -import { withSelect, withDispatch } from '@wordpress/data'; -import { compose } from '@wordpress/compose'; +import { useDispatch, useSelect } from '@wordpress/data'; /** * Internal dependencies */ import { store as editorStore } from '../../store'; -function PostPingbacks( { pingStatus = 'open', ...props } ) { +function PostPingbacks() { + const pingStatus = + useSelect( + ( select ) => + select( editorStore ).getEditedPostAttribute( 'ping_status' ), + [] + ) ?? 'open'; + const { editPost } = useDispatch( editorStore ); const onTogglePingback = () => - props.editPost( { + editPost( { ping_status: pingStatus === 'open' ? 'closed' : 'open', } ); @@ -27,14 +33,4 @@ function PostPingbacks( { pingStatus = 'open', ...props } ) { ); } -export default compose( [ - withSelect( ( select ) => { - return { - pingStatus: - select( editorStore ).getEditedPostAttribute( 'ping_status' ), - }; - } ), - withDispatch( ( dispatch ) => ( { - editPost: dispatch( editorStore ).editPost, - } ) ), -] )( PostPingbacks ); +export default PostPingbacks; From 08ae4a0d21ec56fb837c200043bb565e873bc0ea Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Tue, 1 Aug 2023 15:41:40 +0300 Subject: [PATCH 2/2] Move default inside --- .../editor/src/components/post-pingbacks/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/editor/src/components/post-pingbacks/index.js b/packages/editor/src/components/post-pingbacks/index.js index 582ad5661eb393..d6e1c419ee6f9d 100644 --- a/packages/editor/src/components/post-pingbacks/index.js +++ b/packages/editor/src/components/post-pingbacks/index.js @@ -11,12 +11,12 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { store as editorStore } from '../../store'; function PostPingbacks() { - const pingStatus = - useSelect( - ( select ) => - select( editorStore ).getEditedPostAttribute( 'ping_status' ), - [] - ) ?? 'open'; + const pingStatus = useSelect( + ( select ) => + select( editorStore ).getEditedPostAttribute( 'ping_status' ) ?? + 'open', + [] + ); const { editPost } = useDispatch( editorStore ); const onTogglePingback = () => editPost( {