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

Function Post

examples/react/basic-graphql-request/src/index.tsx:142–173  ·  view source on GitHub ↗
({
  postId,
  setPostId,
}: {
  postId: number
  setPostId: React.Dispatch<React.SetStateAction<number>>
})

Source from the content-addressed store, hash-verified

140}
141
142function Post({
143 postId,
144 setPostId,
145}: {
146 postId: number
147 setPostId: React.Dispatch<React.SetStateAction<number>>
148}) {
149 const { status, data, error, isFetching } = usePost(postId)
150
151 return (
152 <div>
153 <div>
154 <a onClick={() => setPostId(-1)} href="#">
155 Back
156 </a>
157 </div>
158 {!postId || status === 'pending' ? (
159 'Loading...'
160 ) : status === 'error' ? (
161 <span>Error: {error.message}</span>
162 ) : (
163 <>
164 <h1>{data.title}</h1>
165 <div>
166 <p>{data.body}</p>
167 </div>
168 <div>{isFetching ? 'Background Updating...' : ' '}</div>
169 </>
170 )}
171 </div>
172 )
173}
174
175const rootElement = document.getElementById('root')
176if (!rootElement) throw new Error('Missing #root element')

Callers

nothing calls this directly

Calls 1

usePostFunction · 0.70

Tested by

no test coverage detected