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

Function Post

examples/preact/basic-graphql-request/src/index.tsx:85–118  ·  view source on GitHub ↗
({
  postId,
  setPostId,
}: {
  postId: string
  setPostId: (postId: string | null) => void
})

Source from the content-addressed store, hash-verified

83}
84
85function Post({
86 postId,
87 setPostId,
88}: {
89 postId: string
90 setPostId: (postId: string | null) => void
91}) {
92 const { status, data, error, isFetching } = useQuery(
93 postsQueries.detail(postId),
94 )
95
96 return (
97 <div>
98 <div>
99 <a onClick={() => setPostId(null)} href="#">
100 Back
101 </a>
102 </div>
103 {status === 'pending' ? (
104 'Loading...'
105 ) : status === 'error' ? (
106 <span>Error: {error.message}</span>
107 ) : (
108 <>
109 <h1>{data.title}</h1>
110 <div>
111 <p>{data.body}</p>
112 </div>
113 <div>{isFetching ? 'Background Updating...' : ' '}</div>
114 </>
115 )}
116 </div>
117 )
118}
119
120const rootElement = document.getElementById('root')
121if (!rootElement) throw new Error('Missing #root element')

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected