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

Function Post

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

Source from the content-addressed store, hash-verified

109}
110
111function Post(props: { postId: number; setPostId: Setter<number> }) {
112 // You can even leave out the queryFn and just go straight into options
113 const state = useQuery<Post>(() => ({
114 queryKey: [`/posts/${props.postId}`],
115 enabled: !!props.postId,
116 }))
117
118 return (
119 <div>
120 <div>
121 <a onClick={() => props.setPostId(-1)} href="#">
122 Back
123 </a>
124 </div>
125 <Switch>
126 <Match when={!props.postId || state.status === 'pending'}>
127 Loading...
128 </Match>
129 <Match when={state.status === 'error'}>
130 <span>Error: {(state.error as Error).message}</span>
131 </Match>
132 <Match when={state.data !== undefined}>
133 <>
134 <h1>{state.data?.title}</h1>
135 <div>
136 <p>{state.data?.body}</p>
137 </div>
138 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
139 </>
140 </Match>
141 </Switch>
142 </div>
143 )
144}
145
146const root = document.getElementById('root')
147if (!root) throw new Error('Missing #root element')

Callers

nothing calls this directly

Calls 2

useQueryFunction · 0.90
setPostIdMethod · 0.45

Tested by

no test coverage detected