Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: No need to memorize callback in 'SwapTemplateButton' #61049

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading