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 setShowProjects((old) => {
47 if (!old) {
48 queryClient.query(projectsQueryOptions).catch(noop)
49 }
50 return !old
51 })
52 }}
53 >
54 {showProjects ? 'Hide Projects' : 'Show Projects'}
55 </Button>
56β
57 <hr />
58β
59 <QueryErrorResetBoundary>
60 {({ reset }) => (
61 <ErrorBoundary
62 fallbackRender={({ error, resetErrorBoundary }) => (
63 <div>
64 There was an error!{' '}
65 <Button onClick={() => resetErrorBoundary()}>Try again</Button>
66 <pre style={{ whiteSpace: 'normal' }}>{error.message}</pre>
67 </div>
68 )}
69 onReset={reset}
70 >
71 {showProjects ? (
72 <React.Suspense fallback={<h1>Loading projects...</h1>}>
73 {activeProject ? (
74 <Project
75 activeProject={activeProject}
76 setActiveProject={setActiveProject}
77 />
78 ) : (
79 <Projects setActiveProject={setActiveProject} />
80 )}
81 </React.Suspense>
82 ) : null}
83 </ErrorBoundary>
84 )}
85 </QueryErrorResetBoundary>
86 <ReactQueryDevtools initialIsOpen />
87 </>
88 )
89}
90β
91const rootElement = document.getElementById('root')
92if (!rootElement) throw new Error('Missing #root element')
93ReactDOM.createRoot(rootElement).render(<App />)