Skip to content

Commit 361592b

Browse files
committed
feat: adjust throwOnError logic in suspense mode
1 parent d8c6880 commit 361592b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { type QueryClient, useQueryClient } from '@tanstack/react-query'
1+
import {
2+
type Query,
3+
type QueryClient,
4+
useQueryClient,
5+
} from '@tanstack/react-query'
26

37
import type { Middleware, inferQueryKey } from './types'
48

@@ -35,12 +39,15 @@ export const withMiddleware = (
3539
}
3640
}
3741

42+
const defaultThrowOnError = (_error: unknown, query: Query) =>
43+
query.state.data === undefined
44+
3845
export const suspenseOptions = {
3946
enabled: true,
4047
suspense: true,
41-
throwOnError: true,
48+
throwOnError: defaultThrowOnError,
4249
// Compatible with ReactQuery v4
43-
useErrorBoundary: true,
50+
useErrorBoundary: defaultThrowOnError,
4451
}
4552

4653
export const getKey = <TVariables = void>(

0 commit comments

Comments
 (0)