Skip to content

Commit

Permalink
Editor: No need to memorize callback in 'SwapTemplateButton' (#61049)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2024
1 parent 6d444aa commit 3a38dd8
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useMemo, useState, useCallback } from '@wordpress/element';
import { useMemo, useState } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
import { MenuItem, Modal } from '@wordpress/components';
Expand All @@ -18,9 +18,6 @@ import { useAvailableTemplates, useEditedPostContext } from './hooks';

export default function SwapTemplateButton( { onClick } ) {
const [ showModal, setShowModal ] = useState( false );
const onClose = useCallback( () => {
setShowModal( false );
}, [] );
const { postType, postId } = useEditedPostContext();
const availableTemplates = useAvailableTemplates( postType );
const { editEntityRecord } = useDispatch( coreStore );
Expand All @@ -35,7 +32,7 @@ export default function SwapTemplateButton( { onClick } ) {
{ template: template.name },
{ undoIgnore: true }
);
onClose(); // Close the template suggestions modal first.
setShowModal( false ); // Close the template suggestions modal first.
onClick();
};
return (
Expand All @@ -46,7 +43,7 @@ export default function SwapTemplateButton( { onClick } ) {
{ showModal && (
<Modal
title={ __( 'Choose a template' ) }
onRequestClose={ onClose }
onRequestClose={ () => setShowModal( false ) }
overlayClassName="editor-post-template__swap-template-modal"
isFullScreen
>
Expand Down

0 comments on commit 3a38dd8

Please sign in to comment.