MCPcopy
hub / github.com/TanStack/query / Posts

Function Posts

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

Source from the content-addressed store, hash-verified

34}
35
36function Posts(props: { setPostId: Setter<number> }) {
37 const state = createPosts()
38
39 return (
40 <div>
41 <h1>Posts</h1>
42 <div>
43 <Switch>
44 <Match when={state.status === 'pending'}>Loading...</Match>
45 <Match when={state.status === 'error'}>
46 <span>Error: {(state.error as Error).message}</span>
47 </Match>
48 <Match when={state.data !== undefined}>
49 <>
50 <div>
51 <For each={state.data}>
52 {(post) => (
53 <p>
54 <a
55 onClick={() => props.setPostId(post.id)}
56 href="#"
57 style={
58 // We can access the query data here to show bold links for
59 // ones that are cached
60 queryClient.getQueryData(['post', post.id])
61 ? {
62 'font-weight': 'bold',
63 color: 'green',
64 }
65 : {}
66 }
67 >
68 {post.title}
69 </a>
70 </p>
71 )}
72 </For>
73 </div>
74 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
75 </>
76 </Match>
77 </Switch>
78 </div>
79 </div>
80 )
81}
82
83const getPostById = async (id: number): Promise<Post> => {
84 const response = await fetch(

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…