Skip to content

Commit

Permalink
Follow recommendation to use useSelect hook, instead of using select(…
Browse files Browse the repository at this point in the history
…) directly in React components
  • Loading branch information
carstingaxion committed Jun 4, 2024
1 parent 1632d84 commit 0c1cf66
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
import { select } from '@wordpress/data';
import { useSelect } from '@wordpress/data';

const CreateNewPostLink = ( postType ) => {
const CreateNewPostLink = ( { postType } ) => {
const newPostUrl = addQueryArgs( 'post-new.php', {
post_type: postType,
} );

const addNewItemLabel =
select( coreStore ).getPostType( postType )?.labels?.add_new_item;

const addNewItemLabel = useSelect(
( select ) => {
const { getPostType } = select( coreStore );
return getPostType( postType )?.labels?.add_new_item;
},
[ postType ]
);
return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
Expand Down

0 comments on commit 0c1cf66

Please sign in to comment.