MCPcopy Create free account
hub / github.com/developmentseed/stac-react / useCollections

Function useCollections

src/hooks/useCollections.ts:14–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12}
13
14function useCollections(): StacCollectionsHook {
15 const { stacApi } = useStacApiContext();
16
17 const fetchCollections = async (): Promise<CollectionsResponse> => {
18 if (!stacApi) throw new Error('No STAC API configured');
19 const response: Response = await stacApi.getCollections();
20 return handleStacResponse<CollectionsResponse>(response);
21 };
22
23 const {
24 data: collections,
25 error,
26 isLoading,
27 isFetching,
28 refetch,
29 } = useQuery<CollectionsResponse, ApiError>({
30 queryKey: generateCollectionsQueryKey(),
31 queryFn: fetchCollections,
32 enabled: !!stacApi,
33 retry: false,
34 });
35
36 return {
37 collections,
38 refetch,
39 isLoading,
40 isFetching,
41 error,
42 };
43}
44
45export default useCollections;

Callers 3

MainFunction · 0.85
useStacApi.test.tsFile · 0.85

Calls 2

useStacApiContextFunction · 0.90

Tested by

no test coverage detected