Skip to content

Commit

Permalink
Memoize the createPageEntity callback to stop useBlockEditorSettings …
Browse files Browse the repository at this point in the history
…useMemo return firing on every keystroke (#54580)
  • Loading branch information
glendaviesnz authored Sep 19, 2023
1 parent aeb7be8 commit 6999011
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { Platform, useMemo } from '@wordpress/element';
import { Platform, useMemo, useCallback } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import {
store as coreStore,
Expand Down Expand Up @@ -182,14 +182,19 @@ function useBlockEditorSettings( settings, hasTemplate ) {
* @param {Object} options parameters for the post being created. These mirror those used on 3rd param of saveEntityRecord.
* @return {Object} the post type object that was created.
*/
const createPageEntity = ( options ) => {
if ( ! userCanCreatePages ) {
return Promise.reject( {
message: __( 'You do not have permission to create Pages.' ),
} );
}
return saveEntityRecord( 'postType', 'page', options );
};
const createPageEntity = useCallback(
( options ) => {
if ( ! userCanCreatePages ) {
return Promise.reject( {
message: __(
'You do not have permission to create Pages.'
),
} );
}
return saveEntityRecord( 'postType', 'page', options );
},
[ saveEntityRecord, userCanCreatePages ]
);

return useMemo(
() => ( {
Expand Down

0 comments on commit 6999011

Please sign in to comment.