From be7dbf9696d934bf4681e4b5c2ec8f8c83c8e8b9 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 18 Dec 2023 16:24:07 +0400 Subject: [PATCH] Block Editor: Combine selectors in the 'BackgroundImagePanelItem' component --- packages/block-editor/src/hooks/background.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/hooks/background.js b/packages/block-editor/src/hooks/background.js index b75dc95b75241..73370b21fbde6 100644 --- a/packages/block-editor/src/hooks/background.js +++ b/packages/block-editor/src/hooks/background.js @@ -144,21 +144,22 @@ function InspectorImagePreview( { label, filename, url: imgUrl } ) { } function BackgroundImagePanelItem( { clientId, setAttributes } ) { - const style = useSelect( - ( select ) => - select( blockEditorStore ).getBlockAttributes( clientId )?.style, + const { style, mediaUpload } = useSelect( + ( select ) => { + const { getBlockAttributes, getSettings } = + select( blockEditorStore ); + + return { + style: getBlockAttributes( clientId )?.style, + mediaUpload: getSettings().mediaUpload, + }; + }, [ clientId ] ); const { id, title, url } = style?.background?.backgroundImage || {}; const replaceContainerRef = useRef(); - const { mediaUpload } = useSelect( ( select ) => { - return { - mediaUpload: select( blockEditorStore ).getSettings().mediaUpload, - }; - } ); - const { createErrorNotice } = useDispatch( noticesStore ); const onUploadError = ( message ) => { createErrorNotice( message, { type: 'snackbar' } );