Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/pages/reference/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
isPlaceholderData,
isPreviousData,
isRefetchError,
isRefetching,
isStale,
isSuccess,
refetch,
Expand Down Expand Up @@ -218,6 +219,9 @@ const result = useQuery({
- `isFetching: boolean`
- Is `true` whenever a request is in-flight, which includes initial `loading` as well as background refetches.
- Will be `true` if the query is currently fetching, including background fetching.
- `isRefetching: boolean`
- Is `true` whenever a background refetch is in-flight, which _does not_ include initial `loading`
- Is the same as `isFetching && !isLoading`
- `failureCount: number`
- The failure count for the query.
- Incremented every time the query fails.
Expand Down
1 change: 1 addition & 0 deletions src/core/queryObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ export class QueryObserver<
state.dataUpdateCount > queryInitialState.dataUpdateCount ||
state.errorUpdateCount > queryInitialState.errorUpdateCount,
isFetching,
isRefetching: isFetching && status !== 'loading',
isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
isPlaceholderData,
isPreviousData,
Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export interface QueryObserverBaseResult<TData = unknown, TError = unknown> {
isPlaceholderData: boolean
isPreviousData: boolean
isRefetchError: boolean
isRefetching: boolean
isStale: boolean
isSuccess: boolean
refetch: (
Expand Down
2 changes: 2 additions & 0 deletions src/react/tests/useInfiniteQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('useInfiniteQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: false,
refetch: expect.any(Function),
Expand Down Expand Up @@ -116,6 +117,7 @@ describe('useInfiniteQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: true,
refetch: expect.any(Function),
Expand Down
10 changes: 10 additions & 0 deletions src/react/tests/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe('useQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: false,
refetch: expect.any(Function),
Expand All @@ -201,6 +202,7 @@ describe('useQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: true,
refetch: expect.any(Function),
Expand Down Expand Up @@ -254,6 +256,7 @@ describe('useQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: false,
refetch: expect.any(Function),
Expand All @@ -277,6 +280,7 @@ describe('useQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: false,
refetch: expect.any(Function),
Expand All @@ -300,6 +304,7 @@ describe('useQuery', () => {
isPlaceholderData: false,
isPreviousData: false,
isRefetchError: false,
isRefetching: false,
isStale: true,
isSuccess: false,
refetch: expect.any(Function),
Expand Down Expand Up @@ -819,6 +824,7 @@ describe('useQuery', () => {
'data',
'isFetching',
'isLoading',
'isRefetching',
'isSuccess',
'status',
],
Expand Down Expand Up @@ -1155,24 +1161,28 @@ describe('useQuery', () => {
expect(states[0]).toMatchObject({
data: undefined,
isFetching: true,
isRefetching: false,
isSuccess: false,
isStale: true,
})
expect(states[1]).toMatchObject({
data: 1,
isFetching: false,
isRefetching: false,
isSuccess: true,
isStale: false,
})
expect(states[2]).toMatchObject({
data: 1,
isFetching: true,
isRefetching: true,
isSuccess: true,
isStale: true,
})
expect(states[3]).toMatchObject({
data: 2,
isFetching: false,
isRefetching: false,
isSuccess: true,
isStale: false,
})
Expand Down