Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upkeep: add TS support for useTaxonomy hook #303

Merged
merged 11 commits into from
May 3, 2024
17 changes: 17 additions & 0 deletions hooks/use-taxonomy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import type { Taxonomy } from '@wordpress/core-data';

export function useTaxonomy(taxonomyName: string) {
return useSelect(
(select) => {
const { getTaxonomy, hasFinishedResolution } = select(coreStore);

const hasResolvedTaxonomy = hasFinishedResolution('getTaxonomy', [taxonomyName]);
const taxonomy = getTaxonomy(taxonomyName);

return [taxonomy, hasResolvedTaxonomy];
},
[taxonomyName],
) as [ Taxonomy, boolean ];
}
Loading
Loading