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

App.tsx

51 lines1.4 KB

1import { Suspense } from 'preact/compat'
2import { useSuspenseQuery } from '@tanstack/preact-query'
3import ErrorBoundary from './ErrorBoundary'
4import { waitQueries } from './services/wait/queries'
5​
6export const waits = [100, 200, 300, 400, 500, 600, 700]
7export const combinedWaits = [800, 900, 1000]
8​
9function MyComponent(props: { wait: number }) {
10 const { data } = useSuspenseQuery(waitQueries.detail(props.wait))
11​
12 return <div>result: {data}</div>
14​
15export default function App() {
16 return (
17 <>
18 {waits.map((wait) => (
19 <ErrorBoundary
20 key={wait}
21 fallback={(error) => <div>error: {error.message}</div>}
22 >
23 <Suspense fallback={<div>waiting {wait}....</div>}>
24 <MyComponent wait={wait} />
25 </Suspense>
26 </ErrorBoundary>
27 ))}
28​
29 <fieldset>
30 <legend>
31 combined <code>Suspense</code>-container
32 </legend>
33 <ErrorBoundary fallback={(error) => <div>error: {error.message}</div>}>
34 <Suspense
35 fallback={
36 <>
37 {combinedWaits.map((wait) => (
38 <div key={wait}>waiting {wait}....</div>
39 ))}
40 </>
41 }
42 >
43 {combinedWaits.map((wait) => (
44 <MyComponent key={wait} wait={wait} />
45 ))}
46 </Suspense>
47 </ErrorBoundary>
48 </fieldset>
49 </>
50 )