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

ErrorBoundary.tsx

29 lines566 Bytes

1import { useErrorBoundary } from 'preact/hooks'
2import type { ComponentChildren } from 'preact'
3​
4export default function ErrorBoundary({
5 children,
6 onReset,
7 fallbackRender,
8}: {
9 children: ComponentChildren
10 onReset: () => void
11 fallbackRender: (props: {
12 error: Error
13 resetErrorBoundary: () => void
14 }) => ComponentChildren
15}) {
16 const [error, resetError] = useErrorBoundary()
17​
18 if (error) {
19 return fallbackRender({
20 error,
21 resetErrorBoundary: () => {
22 onReset()
23 resetError()
24 },
25 })
26 }
27​
28 return children