Skip to content

Commit

Permalink
Merge pull request #1057 from alleyinteractive/issue-1055
Browse files Browse the repository at this point in the history
Issue 1055
  • Loading branch information
attackant authored Jan 30, 2024
2 parents 057a6c3 + 0df4315 commit 2fec435
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 9 additions & 5 deletions assets/js/components/term-selector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export default function TermSelector({

// If the debounced search term changes, search for results from the API.
useEffect(() => {
if (debouncedSearchTerm) {
(async () => {
const newSearchResults = await apiFetch({ path: `/${taxonomies[taxonomy].rest_namespace}/${taxonomies[taxonomy].rest_base}?search=${debouncedSearchTerm}` });
const fetchTermData = async () => {
if (debouncedSearchTerm) {
const newSearchResults = await apiFetch({
path: `/${taxonomies[taxonomy].rest_namespace}/${taxonomies[taxonomy].rest_base}?search=${debouncedSearchTerm}`,
});
newSearchResults.forEach((result) => termCache.set(result));
setSearchResults(newSearchResults);
})();
}
}
};

fetchTermData();
}, [debouncedSearchTerm]); // eslint-disable-line react-hooks/exhaustive-deps

return (
Expand Down
11 changes: 8 additions & 3 deletions assets/js/services/hooks/use-taxonomies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import { useEffect, useState } from 'react';
export default function useTaxonomies() {
const [taxonomies, setTaxonomies] = useState({});

useEffect(() => (async () => {
setTaxonomies(await apiFetch({ path: '/wp/v2/taxonomies' }));
})(), []);
useEffect(() => {
const fetchTaxonomies = async () => {
const response = await apiFetch({ path: '/wp/v2/taxonomies' });
setTaxonomies(response);
};

fetchTaxonomies();
}, []);

return taxonomies;
}

0 comments on commit 2fec435

Please sign in to comment.