Skip to content

Commit

Permalink
Update: Avoid two useSelect calls on PostActions. (#60752)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
  • Loading branch information
jorgefilipecosta and jorgefilipecosta authored Apr 15, 2024
1 parent b06dbb9 commit a5882a2
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/editor/src/components/post-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useMemo, useState, Fragment, Children } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
Expand Down Expand Up @@ -41,24 +40,17 @@ const POST_ACTIONS_WHILE_EDITING = [
];

export default function PostActions( { onActionPerformed } ) {
const { postType, postId } = useSelect( ( select ) => {
const { getCurrentPostType, getCurrentPostId } = select( editorStore );
const { postType, item } = useSelect( ( select ) => {
const { getCurrentPostType, getCurrentPost } = select( editorStore );
return {
postType: getCurrentPostType(),
postId: getCurrentPostId(),
item: getCurrentPost(),
};
} );
const actions = usePostActions(
onActionPerformed,
POST_ACTIONS_WHILE_EDITING
);
const item = useSelect(
( select ) => {
const { getEditedEntityRecord } = select( coreStore );
return getEditedEntityRecord( 'postType', postType, postId );
},
[ postType, postId ]
);

const { primaryActions, secondaryActions } = useMemo( () => {
return actions.reduce(
Expand Down

0 comments on commit a5882a2

Please sign in to comment.