MCPcopy Index your code
hub / github.com/TanStack/query / Posts

Function Posts

examples/solid/basic-graphql-request/src/index.tsx:72–117  ·  view source on GitHub ↗
(props: { setPostId: Setter<number> })

Source from the content-addressed store, hash-verified

70}
71
72function Posts(props: { setPostId: Setter<number> }) {
73 const state = createPosts()
74
75 return (
76 <div>
77 <h1>Posts</h1>
78 <div>
79 <Switch>
80 <Match when={state.status === 'pending'}>Loading...</Match>
81 <Match when={state.status === 'error'}>
82 <span>Error: {(state.error as Error).message}</span>
83 </Match>
84 <Match when={state.data !== undefined}>
85 <>
86 <div>
87 <For each={state.data}>
88 {(post: any) => (
89 <p>
90 <a
91 onClick={() => props.setPostId(post.id)}
92 href="#"
93 style={
94 // We can find the existing query data here to show bold links for
95 // ones that are cached
96 queryClient.getQueryData(['post', post.id])
97 ? {
98 'font-weight': 'bold',
99 color: 'green',
100 }
101 : {}
102 }
103 >
104 {post.title}
105 </a>
106 </p>
107 )}
108 </For>
109 </div>
110 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
111 </>
112 </Match>
113 </Switch>
114 </div>
115 </div>
116 )
117}
118
119function createPost(postId: Accessor<number>) {
120 return useQuery(() => ({

Callers

nothing calls this directly

Calls 2

createPostsFunction · 0.70
getQueryDataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…