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

Function Posts

examples/solid/basic/src/index.tsx:21–68  ·  view source on GitHub ↗
(props: { setPostId: Setter<number> })

Source from the content-addressed store, hash-verified

19})
20
21function Posts(props: { setPostId: Setter<number> }) {
22 const state = useQuery(() => postsQueries.list())
23
24 return (
25 <div>
26 <h1>Posts</h1>
27 <div>
28 <Switch>
29 <Match when={state.status === 'pending'}>Loading...</Match>
30 <Match when={state.status === 'error'}>
31 <span>Error: {(state.error as Error).message}</span>
32 </Match>
33 <Match when={state.data !== undefined}>
34 <>
35 <div>
36 <For each={state.data}>
37 {(post) => (
38 <p>
39 <a
40 onClick={() => props.setPostId(post.id)}
41 href="#"
42 style={
43 // We can access the query data here to show bold links for
44 // ones that are cached
45 queryClient.getQueryData(
46 postsQueries.detail(post.id).queryKey,
47 )
48 ? {
49 'font-weight': 'bold',
50 color: 'green',
51 }
52 : {}
53 }
54 >
55 {post.title}
56 </a>
57 </p>
58 )}
59 </For>
60 </div>
61 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
62 </>
63 </Match>
64 </Switch>
65 </div>
66 </div>
67 )
68}
69
70function Post(props: { postId: number; setPostId: Setter<number> }) {
71 const state = useQuery(() => postsQueries.detail(props.postId))

Callers

nothing calls this directly

Calls 3

useQueryFunction · 0.90
setPostIdMethod · 0.45
getQueryDataMethod · 0.45

Tested by

no test coverage detected