Skip to content

Commit 44882cb

Browse files
committed
refactor!: rename reload to refetch in hooks API
BREAKING CHANGE: reload() method renamed to refetch() in useCollection, useCollections, and useItem hooks. - Rename reload() to refetch() in useCollection, useCollections, and useItem - Update all tests to use refetch() instead of reload() - Maintain proper async typing with Promise<QueryObserverResult> Using refetch aligns with React Query's naming convention and makes the API more consistent with the underlying library. The function returns the Promise from React Query's refetch directly. Migration: Replace .reload() with .refetch() in your code.
1 parent 0109e59 commit 44882cb

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

src/hooks/useCollection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('useCollection', () => {
8484
);
8585

8686
await act(async () => {
87-
await result.current.reload();
87+
await result.current.refetch();
8888
});
8989

9090
await waitFor(() =>

src/hooks/useCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ type StacCollectionHook = {
99
collection?: Collection;
1010
isLoading: boolean;
1111
isFetching: boolean;
12+
refetch: () => Promise<QueryObserverResult<Collection, ApiErrorType>>;
1213
error?: ApiErrorType;
13-
reload: () => Promise<QueryObserverResult<Collection, ApiErrorType>>;
1414
};
1515

1616
function useCollection(collectionId: string): StacCollectionHook {
@@ -49,8 +49,8 @@ function useCollection(collectionId: string): StacCollectionHook {
4949
collection,
5050
isLoading,
5151
isFetching,
52+
refetch,
5253
error: error as ApiErrorType,
53-
reload: refetch,
5454
};
5555
}
5656

src/hooks/useCollections.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('useCollections', () => {
3333
await waitFor(() => expect(result.current.isLoading).toEqual(false));
3434

3535
await act(async () => {
36-
await result.current.reload();
36+
await result.current.refetch();
3737
});
3838

3939
await waitFor(() => expect(result.current.collections).toEqual({ data: 'reloaded' }));

src/hooks/useCollections.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useStacApiContext } from '../context/useStacApiContext';
77

88
type StacCollectionsHook = {
99
collections?: CollectionsResponse;
10-
reload: () => Promise<QueryObserverResult<CollectionsResponse, ApiErrorType>>;
10+
refetch: () => Promise<QueryObserverResult<CollectionsResponse, ApiErrorType>>;
1111
isLoading: boolean;
1212
isFetching: boolean;
1313
error?: ApiErrorType;
@@ -47,7 +47,7 @@ function useCollections(): StacCollectionsHook {
4747

4848
return {
4949
collections,
50-
reload: refetch,
50+
refetch,
5151
isLoading,
5252
isFetching,
5353
error: error as ApiErrorType,

src/hooks/useItem.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('useItem', () => {
6969
await waitFor(() => expect(result.current.item).toEqual({ id: 'abc' }));
7070

7171
await act(async () => {
72-
await result.current.reload();
72+
await result.current.refetch();
7373
});
7474

7575
await waitFor(() => expect(result.current.item).toEqual({ id: 'abc', description: 'Updated' }));

src/hooks/useItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type ItemHook = {
1010
isLoading: boolean;
1111
isFetching: boolean;
1212
error?: ApiErrorType;
13-
reload: () => Promise<QueryObserverResult<Item, ApiErrorType>>;
13+
refetch: () => Promise<QueryObserverResult<Item, ApiErrorType>>;
1414
};
1515

1616
function useItem(url: string): ItemHook {
@@ -50,7 +50,7 @@ function useItem(url: string): ItemHook {
5050
isLoading,
5151
isFetching,
5252
error: error as ApiErrorType,
53-
reload: refetch,
53+
refetch,
5454
};
5555
}
5656

0 commit comments

Comments
 (0)