Skip to content

Commit 728f346

Browse files
author
ismay
committed
fix(use-data-query): use isFetching for loading state
1 parent e56be92 commit 728f346

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

services/data/src/react/hooks/useDataQuery.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,15 @@ export const useDataQuery = (
5757
const queryKey = [staticQuery, variables]
5858
const queryFn = () => engine.query(staticQuery, { variables })
5959

60-
const {
61-
isIdle,
62-
isLoading: loading,
63-
error,
64-
data,
65-
refetch: queryRefetch,
66-
} = useQuery(queryKey, queryFn, {
67-
enabled,
68-
onSuccess,
69-
onError,
70-
})
60+
const { isIdle, isFetching, error, data, refetch: queryRefetch } = useQuery(
61+
queryKey,
62+
queryFn,
63+
{
64+
enabled,
65+
onSuccess,
66+
onError,
67+
}
68+
)
7169

7270
/**
7371
* Refetch allows a user to update the variables or just
@@ -107,13 +105,12 @@ export const useDataQuery = (
107105
* or an error, so this ensures consistency with the other types.
108106
*/
109107
const ourError = error || undefined
110-
// A query is idle if it is lazy and no initial data is available.
111-
const ourCalled = !isIdle
112108

113109
return {
114110
engine,
115-
called: ourCalled,
116-
loading,
111+
// A query is idle if it is lazy and no initial data is available.
112+
called: !isIdle,
113+
loading: isFetching,
117114
error: ourError,
118115
data,
119116
refetch,

0 commit comments

Comments
 (0)