Open History to see the last commit
1import 'font-awesome/css/font-awesome.min.css'
2import React, { lazy } from 'react'
3import ReactDOM from 'react-dom/client'
4import {
5 QueryClient,
6 QueryClientProvider,
7 QueryErrorResetBoundary,
8 noop,
9 useQueryClient,
10} from '@tanstack/react-query'
11import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
12import { ErrorBoundary } from 'react-error-boundary'
13β
14import { projectsQueryOptions } from './queries'
15β
16import Button from './components/Button'
17β
18const Projects = lazy(() => import('./components/Projects'))
19const Project = lazy(() => import('./components/Project'))
20β
21const queryClient = new QueryClient({
22 defaultOptions: {
23 queries: {
24 retry: 0,
25 },
26 },
27})
28β
29function App() {
30 return (
31 <QueryClientProvider client={queryClient}>
32 <Example />
33 </QueryClientProvider>
34 )
35}
36β
37function Example() {
38 const queryClient = useQueryClient()
39 const [showProjects, setShowProjects] = React.useState(false)
40 const [activeProject, setActiveProject] = React.useState<string | null>(null)
41β
42 return (
43 <>
44 <Button
45 onClick={() => {
46 if (!showProjects) {
47 queryClient.query(projectsQueryOptions).catch(noop)
48 }
49 setShowProjects((old) => !old)
50 }}
51 >
52 {showProjects ? 'Hide Projects' : 'Show Projects'}
53 </Button>
54β
55 <hr />
56β
57 <QueryErrorResetBoundary>
58 {({ reset }) => (
59 <ErrorBoundary
60 fallbackRender={({ error, resetErrorBoundary }) => (
61 <div>
62 There was an error!{' '}
63 <Button onClick={() => resetErrorBoundary()}>Try again</Button>
64 <pre style={{ whiteSpace: 'normal' }}>{error.message}</pre>
65 </div>
66 )}
67 onReset={reset}
68 >
69 {showProjects ? (
70 <React.Suspense fallback={<h1>Loading projects...</h1>}>
71 {activeProject ? (
72 <Project
73 activeProject={activeProject}
74 setActiveProject={setActiveProject}
75 />
76 ) : (
77 <Projects setActiveProject={setActiveProject} />
78 )}
79 </React.Suspense>
80 ) : null}
81 </ErrorBoundary>
82 )}
83 </QueryErrorResetBoundary>
84 <ReactQueryDevtools initialIsOpen />
85 </>
86 )
87}
88β
89const rootElement = document.getElementById('root')
90if (!rootElement) throw new Error('Missing #root element')
91ReactDOM.createRoot(rootElement).render(<App />)