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

Function useCollection

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 2

useStacApiContextFunction · 0.90

Tested by

no test coverage detected