55 useQuery ,
66} from '@tanstack/solid-query'
77import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
8- import { For , Match , Show , Switch , createSignal } from 'solid-js'
9- import { render } from 'solid-js /web'
8+ import { For , Loading , Match , Show , Switch , createSignal } from 'solid-js'
9+ import { render } from '@solidjs /web'
1010import type { Setter } from 'solid-js'
1111import type { QueryFunction } from '@tanstack/solid-query'
1212
@@ -46,9 +46,11 @@ function App() {
4646 loading sequences)
4747 </ strong >
4848 </ p >
49- < Show when = { postId ( ) > - 1 } fallback = { < Posts setPostId = { setPostId } /> } >
50- < Post postId = { postId ( ) } setPostId = { setPostId } />
51- </ Show >
49+ < Loading fallback = { < div > Loading...</ div > } >
50+ < Show when = { postId ( ) > - 1 } fallback = { < Posts setPostId = { setPostId } /> } >
51+ < Post postId = { postId ( ) } setPostId = { setPostId } />
52+ </ Show >
53+ </ Loading >
5254 </ QueryClientProvider >
5355 )
5456}
@@ -70,26 +72,32 @@ function Posts(props: { setPostId: Setter<number> }) {
7072 < >
7173 < div >
7274 < For each = { state . data } >
73- { ( post ) => (
74- < p >
75- < a
76- onClick = { ( ) => props . setPostId ( post . id ) }
77- href = "#"
78- style = {
79- // We can use the queryCache here to show bold links for
80- // ones that are cached
81- queryClient . getQueryData ( [ 'post' , post . id ] )
82- ? {
83- 'font-weight' : 'bold' ,
84- color : 'green' ,
85- }
86- : { }
87- }
88- >
89- { post . title }
90- </ a >
91- </ p >
92- ) }
75+ { ( postAccessor ) => {
76+ const post =
77+ typeof postAccessor === 'function'
78+ ? ( postAccessor as any ) ( )
79+ : postAccessor
80+ return (
81+ < p >
82+ < a
83+ onClick = { ( ) => props . setPostId ( post . id ) }
84+ href = "#"
85+ style = {
86+ // We can use the queryCache here to show bold links for
87+ // ones that are cached
88+ queryClient . getQueryData ( [ 'post' , post . id ] )
89+ ? {
90+ 'font-weight' : 'bold' ,
91+ color : 'green' ,
92+ }
93+ : { }
94+ }
95+ >
96+ { post . title }
97+ </ a >
98+ </ p >
99+ )
100+ } }
93101 </ For >
94102 </ div >
95103 < div > { state . isFetching ? 'Background Updating...' : ' ' } </ div >
0 commit comments