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

Function Posts

examples/solid/default-query-function/src/index.tsx:56–102  ·  view source on GitHub ↗
(props: { setPostId: Setter<number> })

Source from the content-addressed store, hash-verified

54}
55
56function Posts(props: { setPostId: Setter<number> }) {
57 // All you have to do now is pass a key!
58 const state = useQuery<any[]>(() => ({ queryKey: ['/posts'] }))
59
60 return (
61 <div>
62 <h1>Posts</h1>
63 <div>
64 <Switch>
65 <Match when={state.status === 'pending'}>Loading...</Match>
66 <Match when={state.status === 'error'}>
67 <span>Error: {(state.error as Error).message}</span>
68 </Match>
69 <Match when={state.data !== undefined}>
70 <>
71 <div>
72 <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 )}
93 </For>
94 </div>
95 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
96 </>
97 </Match>
98 </Switch>
99 </div>
100 </div>
101 )
102}
103
104function Post(props: { postId: number; setPostId: Setter<number> }) {
105 // You can even leave out the queryFn and just go straight into options

Callers

nothing calls this directly

Calls 2

useQueryFunction · 0.90
getQueryDataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…