-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.ts
25 lines (22 loc) · 934 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// @ts-ignore-next-line - The type definitions for the editor package are incomplete.
import { store as editorStore } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
export const useSelectedTermIds = (taxonomyName: string) => {
return useSelect(
(select) => {
// @ts-ignore-next-line - The type definitions for the core store are incomplete.
const { getTaxonomy, hasFinishedResolution } = select(coreStore);
const taxonomyObject = getTaxonomy(taxonomyName);
const hasResolvedTaxonomyObject: boolean = hasFinishedResolution('getTaxonomy', [
taxonomyName,
]);
const { getEditedPostAttribute } = select(editorStore);
const selectedTermIds: Array<number> | undefined = getEditedPostAttribute(
taxonomyObject?.rest_base,
);
return [selectedTermIds, hasResolvedTaxonomyObject] as const;
},
[taxonomyName],
);
};