MCPcopy Create free account
hub / github.com/TanStack/query / Example

Function Example

examples/solid/suspense/src/index.tsx:34–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34function Example() {
35 const queryClient = useQueryClient()
36 const [showProjects, setShowProjects] = createSignal(false)
37 const [activeProject, setActiveProject] = createSignal<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 <ErrorBoundary
55 fallback={(error: Error, reset) => (
56 <div>
57 There was an error!{' '}
58 <Button onClick={() => reset()}>Try again</Button>
59 <pre style={{ 'white-space': 'normal' }}>{error.message}</pre>
60 </div>
61 )}
62 >
63 <Show when={showProjects()}>
64 <Suspense fallback={<h1>Loading projects...</h1>}>
65 <Show
66 when={activeProject()}
67 fallback={<Projects setActiveProject={setActiveProject} />}
68 >
69 {(project) => (
70 <Project
71 activeProject={project()}
72 setActiveProject={setActiveProject}
73 />
74 )}
75 </Show>
76 </Suspense>
77 </Show>
78 </ErrorBoundary>
79 <SolidQueryDevtools initialIsOpen />
80 </>
81 )
82}
83
84const rootElement = document.getElementById('root')
85if (!rootElement) throw new Error('Missing #root element')

Callers

nothing calls this directly

Calls 3

useQueryClientFunction · 0.90
resetFunction · 0.85
queryMethod · 0.45

Tested by

no test coverage detected