diff --git a/packages/edit-site/src/components/template-actions/rename-menu-item.js b/packages/edit-site/src/components/template-actions/rename-menu-item.js index 9c6368ced17bf8..9f897fcd2e9433 100644 --- a/packages/edit-site/src/components/template-actions/rename-menu-item.js +++ b/packages/edit-site/src/components/template-actions/rename-menu-item.js @@ -17,10 +17,8 @@ import { store as noticesStore } from '@wordpress/notices'; import { decodeEntities } from '@wordpress/html-entities'; export default function RenameMenuItem( { template, onClose } ) { - const [ title, setTitle ] = useState( - decodeEntities( template.title.rendered ) - ); - + const title = decodeEntities( template.title.rendered ); + const [ editedTitle, setEditedTitle ] = useState( title ); const [ isModalOpen, setIsModalOpen ] = useState( false ); const { @@ -39,11 +37,11 @@ export default function RenameMenuItem( { template, onClose } ) { try { await editEntityRecord( 'postType', template.type, template.id, { - title, + title: editedTitle, } ); // Update state before saving rerenders the list. - setTitle( '' ); + setEditedTitle( '' ); setIsModalOpen( false ); onClose(); @@ -73,7 +71,12 @@ export default function RenameMenuItem( { template, onClose } ) { return ( <> - setIsModalOpen( true ) }> + { + setIsModalOpen( true ); + setEditedTitle( title ); + } } + > { __( 'Rename' ) } { isModalOpen && ( @@ -89,8 +92,8 @@ export default function RenameMenuItem( { template, onClose } ) {