Skip to content

Commit af2e27e

Browse files
moshyfawnTkDodo
andauthored
refactor: rename useErrorBoundar option to throwError (#4697)
* ♻️ refactor(query-core): rename useErrorBoundary query option to throwError * ♻️ refactor(react-query): rename useErrorBoundary query option to throwError * ♻️ refactor(react-query): rename useErrorBoundary mutation option to throwError * ♻️ refactor(solid-query): rename useErrorBoundary mutation option to throwError * ♻️ refactor(solid-query): rename useErrorBoundary query option to throwError * ✅ test(react-query): rename useErrorBoundary query option to throwError * ✅ test(react-query): rename useErrorBoundary mutation option to throwError * ✅ test(react-query-devtools): rename useErrorBoundary query option to throwError * ✅ test(solid-query): rename useErrorBoundary query option to throwError * ✅ test(solid-query): rename useErrorBoundary mutation option to throwError * 📝 docs(react-query): rename useErrorBoundary query option to throwError * 📝 docs(react-query): rename useErrorBoundary mutation option to throwError * ♻️ refactor(solid-query): rename useErrorBoundary util option to throwError * ♻️ refactor(react-query): rename useErrorBoundary util option to throwError * 📝 docs(react-query): add throwError to migration guide * 🎨 style: format ThrowError type * ♻️ refactor(query-core): rename throwError query option to throwErrors * ♻️ refactor(react-query): rename throwError query option to throwErrors * ♻️ refactor(react-query): rename throwError mutation option to throwErrors * ✅ test(react-query): rename throwError mutation option to throwErrors * ✅ test(react-query): rename throwError query option to throwErrors * ✅ test(react-query-devtools): rename throwError query option to throwErrors * 📝 docs(react-query): rename throwError mutation option to throwErrors * ✅ test(react-query-devtools): rename throwError query option to throwErrors * ✅ test(solid-query): rename throwError mutation option to throwErrors * ✅ test(solid-query): rename throwError query option to throwErrors * 📝 docs(react-query): rename throwError to throwErrors in migration guide * 📝 docs(react-query): rename throwError to throwErrors in reference * ✅ test(react-query): update suspense test desc Co-authored-by: Dominik Dorfmeister <[email protected]>
1 parent 67ed215 commit af2e27e

30 files changed

+98
-104
lines changed

docs/react/guides/migrating-to-react-query-5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ if you still need to remove a query, you can use `queryClient.removeQueries({que
2626
### The minimum required TypeScript version is now 4.7
2727

2828
Mainly because an important fix was shipped around type inference. Please see this [TypeScript issue](https://github.com/microsoft/TypeScript/issues/43371) for more information.
29+
30+
### The `useErrorBoundary` prop has been renamed to `throwErrors`
31+
32+
To make the `useErrorBoundary` prop more framework-agnostic and avoid confusion with the established React function prefix "`use`" for hooks and the "ErrorBoundary" component name, it has been renamed to `throwErrors` to more accurately reflect its functionality.

docs/react/guides/suspense.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ useQuery({ queryKey, queryFn, suspense: true })
4141

4242
When using suspense mode, `status` states and `error` objects are not needed and are then replaced by usage of the `React.Suspense` component (including the use of the `fallback` prop and React error boundaries for catching errors). Please read the [Resetting Error Boundaries](#resetting-error-boundaries) and look at the [Suspense Example](https://codesandbox.io/s/github/tannerlinsley/react-query/tree/main/examples/react/suspense) for more information on how to set up suspense mode.
4343

44-
In addition to queries behaving differently in suspense mode, mutations also behave a bit differently. By default, instead of supplying the `error` variable when a mutation fails, it will be thrown during the next render of the component it's used in and propagate to the nearest error boundary, similar to query errors. If you wish to disable this, you can set the `useErrorBoundary` option to `false`. If you wish that errors are not thrown at all, you can set the `throwOnError` option to `false` as well!
44+
In addition to queries behaving differently in suspense mode, mutations also behave a bit differently. By default, instead of supplying the `error` variable when a mutation fails, it will be thrown during the next render of the component it's used in and propagate to the nearest error boundary, similar to query errors. If you wish to disable this, you can set the `throwErrors` option to `false`. If you wish that errors are not thrown at all, you can set the `throwOnError` option to `false` as well!
4545

4646
## Resetting Error Boundaries
4747

48-
Whether you are using **suspense** or **useErrorBoundaries** in your queries, you will need a way to let queries know that you want to try again when re-rendering after some error occurred.
48+
Whether you are using **suspense** or **throwErrors** in your queries, you will need a way to let queries know that you want to try again when re-rendering after some error occurred.
4949

5050
Query errors can be reset with the `QueryErrorResetBoundary` component or with the `useQueryErrorResetBoundary` hook.
5151

docs/react/reference/QueryClient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ try {
9595

9696
**Options**
9797

98-
The options for `fetchQuery` are exactly the same as those of [`useQuery`](../reference/useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, onSuccess, onError, onSettled, useErrorBoundary, select, suspense, keepPreviousData, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/tannerlinsley/react-query/blob/361935a12cec6f36d0bd6ba12e84136c405047c5/src/core/types.ts#L83) for more clarity.
98+
The options for `fetchQuery` are exactly the same as those of [`useQuery`](../reference/useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, onSuccess, onError, onSettled, throwErrors, select, suspense, keepPreviousData, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/tannerlinsley/react-query/blob/361935a12cec6f36d0bd6ba12e84136c405047c5/src/core/types.ts#L83) for more clarity.
9999

100100
**Returns**
101101

docs/react/reference/QueryErrorResetBoundary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: QueryErrorResetBoundary
33
title: QueryErrorResetBoundary
44
---
55

6-
When using **suspense** or **useErrorBoundaries** in your queries, you need a way to let queries know that you want to try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can reset any query errors within the boundaries of the component.
6+
When using **suspense** or **throwErrors** in your queries, you need a way to let queries know that you want to try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can reset any query errors within the boundaries of the component.
77

88
```tsx
99
import { QueryErrorResetBoundary } from '@tanstack/react-query'

docs/react/reference/useMutation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
onSuccess,
3030
retry,
3131
retryDelay,
32-
useErrorBoundary,
32+
throwErrors,
3333
meta
3434
})
3535

@@ -82,8 +82,8 @@ mutate(variables, {
8282
- This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds.
8383
- A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff.
8484
- A function like `attempt => attempt * 1000` applies linear backoff.
85-
- `useErrorBoundary: undefined | boolean | (error: TError) => boolean`
86-
- Defaults to the global query config's `useErrorBoundary` value, which is `undefined`
85+
- `throwErrors: undefined | boolean | (error: TError) => boolean`
86+
- Defaults to the global query config's `throwErrors` value, which is `undefined`
8787
- Set this to `true` if you want mutation errors to be thrown in the render phase and propagate to the nearest error boundary
8888
- Set this to `false` to disable the behavior of throwing errors to the error boundary.
8989
- If set to a function, it will be passed the error and should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`)

docs/react/reference/useQuery.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const {
5555
staleTime,
5656
structuralSharing,
5757
suspense,
58-
useErrorBoundary,
58+
throwErrors,
5959
})
6060
```
6161

@@ -178,8 +178,8 @@ const {
178178
- Defaults to `true`
179179
- If set to `false`, structural sharing between query results will be disabled.
180180
- If set to a function, the old and new data values will be passed through this function, which should combine them into resolved data for the query. This way, you can retain references from the old data to improve performance even when that data contains non-serializable values.
181-
- `useErrorBoundary: undefined | boolean | (error: TError, query: Query) => boolean`
182-
- Defaults to the global query config's `useErrorBoundary` value, which is `undefined`
181+
- `throwErrors: undefined | boolean | (error: TError, query: Query) => boolean`
182+
- Defaults to the global query config's `throwErrors` value, which is `undefined`
183183
- Set this to `true` if you want errors to be thrown in the render phase and propagate to the nearest error boundary
184184
- Set this to `false` to disable `suspense`'s default behavior of throwing errors to the error boundary.
185185
- If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`)

packages/query-core/src/queryClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ export class QueryClient {
749749
defaultedOptions.refetchOnReconnect =
750750
defaultedOptions.networkMode !== 'always'
751751
}
752-
if (typeof defaultedOptions.useErrorBoundary === 'undefined') {
753-
defaultedOptions.useErrorBoundary = !!defaultedOptions.suspense
752+
if (typeof defaultedOptions.throwErrors === 'undefined') {
753+
defaultedOptions.throwErrors = !!defaultedOptions.suspense
754754
}
755755

756756
return defaultedOptions as DefaultedQueryObserverOptions<

packages/query-core/src/queryObserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export class QueryObserver<
618618

619619
const includedProps = new Set(notifyOnChangeProps ?? this.trackedProps)
620620

621-
if (this.options.useErrorBoundary) {
621+
if (this.options.throwErrors) {
622622
includedProps.add('error')
623623
}
624624

packages/query-core/src/types.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export interface QueryOptions<
104104
meta?: QueryMeta
105105
}
106106

107-
export type UseErrorBoundary<
107+
export type ThrowErrors<
108108
TQueryFnData,
109109
TError,
110110
TQueryData,
@@ -221,12 +221,7 @@ export interface QueryObserverOptions<
221221
* If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`).
222222
* Defaults to `false`.
223223
*/
224-
useErrorBoundary?: UseErrorBoundary<
225-
TQueryFnData,
226-
TError,
227-
TQueryData,
228-
TQueryKey
229-
>
224+
throwErrors?: ThrowErrors<TQueryFnData, TError, TQueryData, TQueryKey>
230225
/**
231226
* This option can be used to transform or select a part of the data returned by the query function.
232227
*/
@@ -260,7 +255,7 @@ export type DefaultedQueryObserverOptions<
260255
TQueryKey extends QueryKey = QueryKey,
261256
> = WithRequired<
262257
QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
263-
'useErrorBoundary' | 'refetchOnReconnect'
258+
'throwErrors' | 'refetchOnReconnect'
264259
>
265260

266261
export interface InfiniteQueryObserverOptions<
@@ -291,7 +286,7 @@ export type DefaultedInfiniteQueryObserverOptions<
291286
TQueryData,
292287
TQueryKey
293288
>,
294-
'useErrorBoundary' | 'refetchOnReconnect'
289+
'throwErrors' | 'refetchOnReconnect'
295290
>
296291

297292
export interface FetchQueryOptions<
@@ -587,7 +582,7 @@ export interface MutationObserverOptions<
587582
TVariables = void,
588583
TContext = unknown,
589584
> extends MutationOptions<TData, TError, TVariables, TContext> {
590-
useErrorBoundary?: boolean | ((error: TError) => boolean)
585+
throwErrors?: boolean | ((error: TError) => boolean)
591586
}
592587

593588
export interface MutateOptions<

packages/react-query-devtools/src/__tests__/devtools.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ describe('ReactQueryDevtools', () => {
704704

705705
function Page() {
706706
const { data = 'default' } = useQuery(['check'], async () => 'test', {
707-
useErrorBoundary: true,
707+
throwErrors: true,
708708
})
709709

710710
return (
@@ -739,7 +739,7 @@ describe('ReactQueryDevtools', () => {
739739

740740
function Page() {
741741
const { data = 'default' } = useQuery(['check'], async () => 'test', {
742-
useErrorBoundary: true,
742+
throwErrors: true,
743743
context,
744744
})
745745

0 commit comments

Comments
 (0)