Skip to content

Commit a914f22

Browse files
committed
fix: Remove dependency on collections object in useCollections effect hook
1 parent 0945c08 commit a914f22

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@developmentseed/stac-react",
3-
"version": "0.1.0-alpha.8",
3+
"version": "0.1.0-alpha.8.1",
44
"description": "React components and hooks for building STAC-API front-ends",
55
"repository": "[email protected]:developmentseed/stac-react.git",
66
"author": "Oliver Roick <[email protected]>",

src/hooks/useCollections.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ describe('useCollections', () => {
2424
expect(result.current.state).toEqual('IDLE');
2525
});
2626

27+
it('reloads collections', async () => {
28+
fetch
29+
.mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net' })
30+
.mockResponseOnce(JSON.stringify({ data: 'original' }))
31+
.mockResponseOnce(JSON.stringify({ data: 'reloaded' }));
32+
33+
const { result, waitForNextUpdate } = renderHook(
34+
() => useCollections(),
35+
{ wrapper }
36+
);
37+
await waitForNextUpdate();
38+
await waitForNextUpdate();
39+
expect(result.current.collections).toEqual({ data: 'original' });
40+
41+
expect(result.current.state).toEqual('IDLE');
42+
act(() => result.current.reload());
43+
44+
await waitForNextUpdate();
45+
expect(result.current.collections).toEqual({ data: 'reloaded' });
46+
});
47+
2748
it('handles error with JSON response', async () => {
2849
fetch
2950
.mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net' })
@@ -61,25 +82,4 @@ describe('useCollections', () => {
6182
detail: 'Wrong query'
6283
});
6384
});
64-
65-
it('reloads collections', async () => {
66-
fetch
67-
.mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net' })
68-
.mockResponseOnce(JSON.stringify({ data: 'original' }))
69-
.mockResponseOnce(JSON.stringify({ data: 'reloaded' }));
70-
71-
const { result, waitForNextUpdate } = renderHook(
72-
() => useCollections(),
73-
{ wrapper }
74-
);
75-
await waitForNextUpdate();
76-
await waitForNextUpdate();
77-
expect(result.current.collections).toEqual({ data: 'original' });
78-
79-
expect(result.current.state).toEqual('IDLE');
80-
act(() => result.current.reload());
81-
82-
await waitForNextUpdate();
83-
expect(result.current.collections).toEqual({ data: 'reloaded' });
84-
});
8585
});

src/hooks/useCollections.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ function useCollections(): StacCollectionsHook {
3636

3737
useEffect(
3838
() => {
39-
if (stacApi && !collections) {
39+
if (stacApi) {
4040
getCollections();
4141
}
4242
},
43-
[getCollections, stacApi, collections]
43+
[getCollections, stacApi]
4444
);
4545

4646
return {

0 commit comments

Comments
 (0)