@wordpress/block-library
Version:
Block library for the WordPress editor.
22 lines (21 loc) • 816 B
JavaScript
import { store } from "@wordpress/core-data";
import { useSelect } from "@wordpress/data";
// packages/block-library/src/query-title/use-post-type-label.js
/**
* Hook to fetch the singular label for the current post type.
*
* @param {string} contextPostType Context provided post type.
*/
function usePostTypeLabel(contextPostType) {
const currentPostType = useSelect((select) => {
const { getCurrentPostType } = select("core/editor");
return getCurrentPostType();
}, []);
return useSelect((select) => {
const { getPostType } = select(store);
const postType = getPostType(contextPostType || currentPostType);
return { postTypeLabel: postType ? postType.labels.singular_name : "" };
}, [contextPostType, currentPostType]);
}
export { usePostTypeLabel };
//# sourceMappingURL=use-post-type-label.mjs.map