Skip to content

Commit

Permalink
Update: Avoid two useSelect calls on PostActions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 15, 2024
1 parent 06b3537 commit 1f6a58a
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 1f6a58a

Please sign in to comment.