Skip to content

Commit 8bd5971

Browse files
committed
docs(preact-query/reference): replace 'react-error-boundary' example with 'useErrorBoundary'
1 parent 0b75856 commit 8bd5971

4 files changed

Lines changed: 86 additions & 0 deletions

File tree

docs/framework/preact/reference/QueryErrorResetBoundary.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,47 @@ title: QueryErrorResetBoundary
44
ref: docs/framework/react/reference/QueryErrorResetBoundary.md
55
replace: { '@tanstack/react-query': '@tanstack/preact-query' }
66
---
7+
8+
[//]: # 'ReactErrorBoundaryExample'
9+
10+
Preact provides a [`useErrorBoundary` hook](https://preactjs.com/guide/v10/hooks/#useerrorboundary) that you can combine with `QueryErrorResetBoundary`'s `reset`:
11+
12+
```tsx
13+
import { QueryErrorResetBoundary } from '@tanstack/preact-query'
14+
import type { ComponentChildren } from 'preact'
15+
import { useErrorBoundary } from 'preact/hooks'
16+
17+
function ErrorBoundary(props: { onReset: () => void; children: ComponentChildren }) {
18+
const [error, resetError] = useErrorBoundary()
19+
20+
if (error) {
21+
return (
22+
<div>
23+
There was an error!
24+
<Button
25+
onClick={() => {
26+
props.onReset()
27+
resetError()
28+
}}
29+
>
30+
Try again
31+
</Button>
32+
</div>
33+
)
34+
}
35+
36+
return props.children
37+
}
38+
39+
const App = () => (
40+
<QueryErrorResetBoundary>
41+
{({ reset }) => (
42+
<ErrorBoundary onReset={reset}>
43+
<Page />
44+
</ErrorBoundary>
45+
)}
46+
</QueryErrorResetBoundary>
47+
)
48+
```
49+
50+
[//]: # 'ReactErrorBoundaryExample'

docs/framework/preact/reference/useQueryErrorResetBoundary.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,37 @@ title: useQueryErrorResetBoundary
44
ref: docs/framework/react/reference/useQueryErrorResetBoundary.md
55
replace: { '@tanstack/react-query': '@tanstack/preact-query' }
66
---
7+
8+
[//]: # 'ReactErrorBoundaryExample'
9+
10+
Preact provides a [`useErrorBoundary` hook](https://preactjs.com/guide/v10/hooks/#useerrorboundary) that you can combine with `useQueryErrorResetBoundary`'s `reset`:
11+
12+
```tsx
13+
import { useQueryErrorResetBoundary } from '@tanstack/preact-query'
14+
import { useErrorBoundary } from 'preact/hooks'
15+
16+
const App = () => {
17+
const { reset } = useQueryErrorResetBoundary()
18+
const [error, resetError] = useErrorBoundary()
19+
20+
if (error) {
21+
return (
22+
<div>
23+
There was an error!
24+
<Button
25+
onClick={() => {
26+
reset()
27+
resetError()
28+
}}
29+
>
30+
Try again
31+
</Button>
32+
</div>
33+
)
34+
}
35+
36+
return <Page />
37+
}
38+
```
39+
40+
[//]: # 'ReactErrorBoundaryExample'

docs/framework/react/reference/QueryErrorResetBoundary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: QueryErrorResetBoundary
55

66
When using **suspense** or **throwOnError** 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

8+
[//]: # 'ReactErrorBoundaryExample'
9+
810
```tsx
911
import { QueryErrorResetBoundary } from '@tanstack/react-query'
1012
import { ErrorBoundary } from 'react-error-boundary'
@@ -27,3 +29,5 @@ const App = () => (
2729
</QueryErrorResetBoundary>
2830
)
2931
```
32+
33+
[//]: # 'ReactErrorBoundaryExample'

docs/framework/react/reference/useQueryErrorResetBoundary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: useQueryErrorResetBoundary
55

66
This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary defined it will reset them globally:
77

8+
[//]: # 'ReactErrorBoundaryExample'
9+
810
```tsx
911
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
1012
import { ErrorBoundary } from 'react-error-boundary'
@@ -26,3 +28,5 @@ const App = () => {
2628
)
2729
}
2830
```
31+
32+
[//]: # 'ReactErrorBoundaryExample'

0 commit comments

Comments
 (0)