diff --git a/docs/src/pages/reference/useQuery.md b/docs/src/pages/reference/useQuery.md index e55ef3f4e1..b9751c3c89 100644 --- a/docs/src/pages/reference/useQuery.md +++ b/docs/src/pages/reference/useQuery.md @@ -238,6 +238,8 @@ const result = useQuery({ - The failure count for the query. - Incremented every time the query fails. - Reset to `0` when the query succeeds. +- `errorUpdateCount: number` + - The sum of all errors. - `refetch: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise` - A function to manually refetch the query. - If the query errors, the error will only be logged. If you want an error to be thrown, pass the `throwOnError: true` option diff --git a/src/core/queryObserver.ts b/src/core/queryObserver.ts index 439752a9aa..c3fa0f6839 100644 --- a/src/core/queryObserver.ts +++ b/src/core/queryObserver.ts @@ -594,6 +594,7 @@ export class QueryObserver< error, errorUpdatedAt, failureCount: state.fetchFailureCount, + errorUpdateCount: state.errorUpdateCount, isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0, isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || diff --git a/src/core/types.ts b/src/core/types.ts index 25a2b90272..63d04d5e6b 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -328,6 +328,7 @@ export interface QueryObserverBaseResult { error: TError | null errorUpdatedAt: number failureCount: number + errorUpdateCount: number isError: boolean isFetched: boolean isFetchedAfterMount: boolean diff --git a/src/react/tests/useInfiniteQuery.test.tsx b/src/react/tests/useInfiniteQuery.test.tsx index 453142d298..8574c50278 100644 --- a/src/react/tests/useInfiniteQuery.test.tsx +++ b/src/react/tests/useInfiniteQuery.test.tsx @@ -73,6 +73,7 @@ describe('useInfiniteQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 0, + errorUpdateCount: 0, fetchNextPage: expect.any(Function), fetchPreviousPage: expect.any(Function), hasNextPage: undefined, @@ -103,6 +104,7 @@ describe('useInfiniteQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 0, + errorUpdateCount: 0, fetchNextPage: expect.any(Function), fetchPreviousPage: expect.any(Function), hasNextPage: true, diff --git a/src/react/tests/useQuery.test.tsx b/src/react/tests/useQuery.test.tsx index e4d26912bf..77341d1868 100644 --- a/src/react/tests/useQuery.test.tsx +++ b/src/react/tests/useQuery.test.tsx @@ -169,6 +169,7 @@ describe('useQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 0, + errorUpdateCount: 0, isError: false, isFetched: false, isFetchedAfterMount: false, @@ -193,6 +194,7 @@ describe('useQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 0, + errorUpdateCount: 0, isError: false, isFetched: true, isFetchedAfterMount: true, @@ -247,6 +249,7 @@ describe('useQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 0, + errorUpdateCount: 0, isError: false, isFetched: false, isFetchedAfterMount: false, @@ -271,6 +274,7 @@ describe('useQuery', () => { error: null, errorUpdatedAt: 0, failureCount: 1, + errorUpdateCount: 0, isError: false, isFetched: false, isFetchedAfterMount: false, @@ -295,6 +299,7 @@ describe('useQuery', () => { error: 'rejected', errorUpdatedAt: expect.any(Number), failureCount: 2, + errorUpdateCount: 1, isError: true, isFetched: true, isFetchedAfterMount: true,