()
| 32 | } |
| 33 | |
| 34 | function Example() { |
| 35 | const queryClient = useQueryClient() |
| 36 | const [showProjects, setShowProjects] = React.useState(false) |
| 37 | const [activeProject, setActiveProject] = React.useState<string | null>(null) |
| 38 | |
| 39 | return ( |
| 40 | <> |
| 41 | <Button |
| 42 | onClick={() => { |
| 43 | if (!showProjects) { |
| 44 | queryClient.query(projectsQueries.list()).catch(noop) |
| 45 | } |
| 46 | setShowProjects((old) => !old) |
| 47 | }} |
| 48 | > |
| 49 | {showProjects ? 'Hide Projects' : 'Show Projects'} |
| 50 | </Button> |
| 51 | |
| 52 | <hr /> |
| 53 | |
| 54 | <QueryErrorResetBoundary> |
| 55 | {({ reset }) => ( |
| 56 | <ErrorBoundary |
| 57 | fallbackRender={({ error, resetErrorBoundary }) => ( |
| 58 | <div> |
| 59 | There was an error!{' '} |
| 60 | <Button onClick={() => resetErrorBoundary()}>Try again</Button> |
| 61 | <pre style={{ whiteSpace: 'normal' }}>{error.message}</pre> |
| 62 | </div> |
| 63 | )} |
| 64 | onReset={reset} |
| 65 | > |
| 66 | {showProjects ? ( |
| 67 | <React.Suspense fallback={<h1>Loading projects...</h1>}> |
| 68 | {activeProject ? ( |
| 69 | <Project |
| 70 | activeProject={activeProject} |
| 71 | setActiveProject={setActiveProject} |
| 72 | /> |
| 73 | ) : ( |
| 74 | <Projects setActiveProject={setActiveProject} /> |
| 75 | )} |
| 76 | </React.Suspense> |
| 77 | ) : null} |
| 78 | </ErrorBoundary> |
| 79 | )} |
| 80 | </QueryErrorResetBoundary> |
| 81 | <ReactQueryDevtools initialIsOpen /> |
| 82 | </> |
| 83 | ) |
| 84 | } |
| 85 | |
| 86 | const rootElement = document.getElementById('root') |
| 87 | if (!rootElement) throw new Error('Missing #root element') |
nothing calls this directly
no test coverage detected