Skip to content

Commit 505b426

Browse files
committed
fix: Remove collection reload when initialising useCollections
1 parent c48d752 commit 505b426

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/hooks/useCollections.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ function useCollections(): StacCollectionsHook {
1616
const [ state, setState ] = useState<LoadingState>('IDLE');
1717
const [ error, setError ] = useState<ApiError>();
1818

19-
2019
const _getCollections = useCallback(
2120
() => {
2221
if (stacApi) {
2322
setState('LOADING');
24-
setCollections(undefined);
2523

2624
stacApi.getCollections()
2725
.then(response => response.json())
2826
.then(setCollections)
29-
.catch((err) => setError(err))
27+
.catch((err) => {
28+
setError(err);
29+
setCollections(undefined);
30+
})
3031
.finally(() => setState('IDLE'));
3132
}
3233
},
@@ -36,11 +37,11 @@ function useCollections(): StacCollectionsHook {
3637

3738
useEffect(
3839
() => {
39-
if (stacApi) {
40+
if (stacApi && !error && !collections) {
4041
getCollections();
4142
}
4243
},
43-
[getCollections, stacApi]
44+
[getCollections, stacApi, collections, error]
4445
);
4546

4647
return {

src/types/stac.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type DateRange = {
88
from?: string,
99
to?: string
1010
}
11-
type Sortby = {
11+
export type Sortby = {
1212
field: string;
1313
direction: 'asc' | 'desc';
1414
}

0 commit comments

Comments
 (0)