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

Function Post

examples/react/basic-graphql-request/src/index.tsx:89–122  ·  view source on GitHub ↗
({
  postId,
  setPostId,
}: {
  postId: string
  setPostId: React.Dispatch<React.SetStateAction<string | null>>
})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected