Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

QueryErrorResetBoundary.md

78 lines2.0 KB

1---
2id: QueryErrorResetBoundary
3title: QueryErrorResetBoundary
4---
5​
6```ts
7function QueryErrorResetBoundary(props: QueryErrorResetBoundaryProps): Element;
8```
9​
10Defined in: [packages/preact-query/src/QueryErrorResetBoundary.tsx:164](https://github.com/TanStack/query/blob/main/packages/preact-query/src/QueryErrorResetBoundary.tsx#L164)
11​
12When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to
13try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can
14reset any query errors within the boundaries of the component.
15​
16## Parameters
17​
18### props
19​
20[`QueryErrorResetBoundaryProps`](../interfaces/QueryErrorResetBoundaryProps.md)
21​
22The `children` to render.
23​
24<a id="props-properties"></a>
25​
26#### `props` properties
27​
28| Property | Type | Description |
29| ------ | ------ | ------ |
30| <a id="props-property-children"></a> `children` | \| `ComponentChildren` \| [`QueryErrorResetBoundaryFunction`](../type-aliases/QueryErrorResetBoundaryFunction.md) | Either a plain node, or a function that receives the boundary's QueryErrorResetBoundaryValue and returns a node. |
31​
32## Returns
33​
34`Element`
35​
36The `children`, rendered as-is, or called with the boundary's QueryErrorResetBoundaryValue
37if `children` is a function.
38​
39## Example
40​
41```tsx
42import { useErrorBoundary } from 'preact/hooks'
43import type { ComponentChildren } from 'preact'
44import { QueryErrorResetBoundary } from '@tanstack/preact-query'
45​
46function App() {
47 return (
48 <QueryErrorResetBoundary>
49 {({ reset }) => (
50 <ErrorBoundary reset={reset}>
51 <Page />
52 </ErrorBoundary>
53 )}
54 </QueryErrorResetBoundary>
55 )
57​
58function ErrorBoundary({
59 children,
60 reset,
61}: {
62 children: ComponentChildren
63 reset: () => void
64}) {
65 const [error, resetError] = useErrorBoundary(() => reset())
66​
67 if (error) {
68 return (
69 <div>
70 There was an error!
71 <button onClick={() => resetError()}>Try again</button>
72 </div>
73 )
74 }
75​
76 return children
78```