Skip to content

Commit

Permalink
show empty list when no ids (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent authored Feb 1, 2024
1 parent 126ac17 commit f32793d
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@ import { useQuery } from 'react-query';
import API from 'utils/api';

const useGetMetaAnalysesByIds = (metaAnalysisIds: string[] | undefined) => {
return useQuery(
const shouldFetch = metaAnalysisIds && metaAnalysisIds.length > 0;

const result = useQuery(
['meta-analyses', metaAnalysisIds],
() =>
API.NeurosynthServices.MetaAnalysisService.metaAnalysesGet(
false,
metaAnalysisIds || []
),
() => API.NeurosynthServices.MetaAnalysisService.metaAnalysesGet(false, metaAnalysisIds),
{
select: (axiosResponse) => {
const res = axiosResponse.data.results || [];
return res;
},
enabled: shouldFetch,
}
);

if (!shouldFetch) {
return {
data: [],
isLoading: false,
isError: false,
};
}

return result;
};

export default useGetMetaAnalysesByIds;

0 comments on commit f32793d

Please sign in to comment.