Skip to content

Commit f32793d

Browse files
authored
show empty list when no ids (#689)
1 parent 126ac17 commit f32793d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

compose/neurosynth-frontend/src/hooks/metaAnalyses/useGetMetaAnalysesByIds.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@ import { useQuery } from 'react-query';
22
import API from 'utils/api';
33

44
const useGetMetaAnalysesByIds = (metaAnalysisIds: string[] | undefined) => {
5-
return useQuery(
5+
const shouldFetch = metaAnalysisIds && metaAnalysisIds.length > 0;
6+
7+
const result = useQuery(
68
['meta-analyses', metaAnalysisIds],
7-
() =>
8-
API.NeurosynthServices.MetaAnalysisService.metaAnalysesGet(
9-
false,
10-
metaAnalysisIds || []
11-
),
9+
() => API.NeurosynthServices.MetaAnalysisService.metaAnalysesGet(false, metaAnalysisIds),
1210
{
1311
select: (axiosResponse) => {
1412
const res = axiosResponse.data.results || [];
1513
return res;
1614
},
15+
enabled: shouldFetch,
1716
}
1817
);
18+
19+
if (!shouldFetch) {
20+
return {
21+
data: [],
22+
isLoading: false,
23+
isError: false,
24+
};
25+
}
26+
27+
return result;
1928
};
2029

2130
export default useGetMetaAnalysesByIds;

0 commit comments

Comments
 (0)