Skip to content

Commit

Permalink
feat: expose errorUpdateCount on useQuery (#3532)
Browse files Browse the repository at this point in the history
* expose errorUpdateCount on useQuery

* refactored test slightly

* Update docs/src/pages/reference/useQuery.md

as  suggested

Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>

* removed the first click as we fetch on default,

* prettier

* added errorUpdateCount to failed tests.

* prettier

Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
  • Loading branch information
OmerCohenAviv and TkDodo committed Apr 22, 2022
1 parent 48ec8cf commit 558878c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/pages/reference/useQuery.md
Expand Up @@ -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<UseQueryResult>`
- 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
Expand Down
1 change: 1 addition & 0 deletions src/core/queryObserver.ts
Expand Up @@ -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 ||
Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Expand Up @@ -328,6 +328,7 @@ export interface QueryObserverBaseResult<TData = unknown, TError = unknown> {
error: TError | null
errorUpdatedAt: number
failureCount: number
errorUpdateCount: number
isError: boolean
isFetched: boolean
isFetchedAfterMount: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/react/tests/useInfiniteQuery.test.tsx
Expand Up @@ -73,6 +73,7 @@ describe('useInfiniteQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 0,
errorUpdateCount: 0,
fetchNextPage: expect.any(Function),
fetchPreviousPage: expect.any(Function),
hasNextPage: undefined,
Expand Down Expand Up @@ -103,6 +104,7 @@ describe('useInfiniteQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 0,
errorUpdateCount: 0,
fetchNextPage: expect.any(Function),
fetchPreviousPage: expect.any(Function),
hasNextPage: true,
Expand Down
5 changes: 5 additions & 0 deletions src/react/tests/useQuery.test.tsx
Expand Up @@ -169,6 +169,7 @@ describe('useQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 0,
errorUpdateCount: 0,
isError: false,
isFetched: false,
isFetchedAfterMount: false,
Expand All @@ -193,6 +194,7 @@ describe('useQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 0,
errorUpdateCount: 0,
isError: false,
isFetched: true,
isFetchedAfterMount: true,
Expand Down Expand Up @@ -247,6 +249,7 @@ describe('useQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 0,
errorUpdateCount: 0,
isError: false,
isFetched: false,
isFetchedAfterMount: false,
Expand All @@ -271,6 +274,7 @@ describe('useQuery', () => {
error: null,
errorUpdatedAt: 0,
failureCount: 1,
errorUpdateCount: 0,
isError: false,
isFetched: false,
isFetchedAfterMount: false,
Expand All @@ -295,6 +299,7 @@ describe('useQuery', () => {
error: 'rejected',
errorUpdatedAt: expect.any(Number),
failureCount: 2,
errorUpdateCount: 1,
isError: true,
isFetched: true,
isFetchedAfterMount: true,
Expand Down

1 comment on commit 558878c

@vercel
Copy link

@vercel vercel bot commented on 558878c Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.