Skip to content

Commit

Permalink
fix: fix collections not being fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
bard committed Dec 18, 2023
1 parent dd04719 commit ce97398
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ export const useCategory = (
): SWRResponse<SearchBasedProjectCategory | undefined> => {
const dataLayer = useDataLayer();

return useSWR(["categories"], async () => {
return useSWR(id === null ? null : ["categories"], async () => {
if (id === null) {
return undefined;
} else {
const { category } = await dataLayer.query({
type: "search-based-project-category",
id,
});
return category === null ? undefined : category;
// The first argument to useSRW will ensure that this function never gets
// called if options is `null`. If it's still called, we fail early and
// clearly.
throw new Error("Bug");
}

const { category } = await dataLayer.query({
type: "search-based-project-category",
id,
});
return category === null ? undefined : category;
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const useCollection = (
id,
});

// TODObard return null instead of undefined if not found
return collection === null ? undefined : collection;
});
};

0 comments on commit ce97398

Please sign in to comment.