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

Function Posts

examples/solid/basic-graphql-request/src/index.tsx:38–85  ·  view source on GitHub ↗
(props: { setPostId: Setter<string | null> })

Source from the content-addressed store, hash-verified

36}
37
38function Posts(props: { setPostId: Setter<string | null> }) {
39 const state = useQuery(() => postsQueries.list())
40
41 return (
42 <div>
43 <h1>Posts</h1>
44 <div>
45 <Switch>
46 <Match when={state.status === 'pending'}>Loading...</Match>
47 <Match when={state.status === 'error'}>
48 <span>Error: {(state.error as Error).message}</span>
49 </Match>
50 <Match when={state.data !== undefined}>
51 <>
52 <div>
53 <For each={state.data}>
54 {(post) => (
55 <p>
56 <a
57 onClick={() => props.setPostId(post.id)}
58 href="#"
59 style={
60 // We can find the existing query data here to show bold links for
61 // ones that are cached
62 queryClient.getQueryData(
63 postsQueries.detail(post.id).queryKey,
64 )
65 ? {
66 'font-weight': 'bold',
67 color: 'green',
68 }
69 : {}
70 }
71 >
72 {post.title}
73 </a>
74 </p>
75 )}
76 </For>
77 </div>
78 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
79 </>
80 </Match>
81 </Switch>
82 </div>
83 </div>
84 )
85}
86
87function Post(props: { postId: string; setPostId: Setter<string | null> }) {
88 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