Skip to content

Commit

Permalink
add TS support for useTaxonomy hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Mar 3, 2024
1 parent 049be1a commit ded2081
Show file tree
Hide file tree
Showing 3 changed files with 1,882 additions and 217 deletions.
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

0 comments on commit ded2081

Please sign in to comment.