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

Function Post

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

Source from the content-addressed store, hash-verified

97}
98
99function Post({
100 postId,
101 setPostId,
102}: {
103 postId: number
104 setPostId: React.Dispatch<React.SetStateAction<number>>
105}) {
106 const { status, data, error, isFetching } = usePost(postId)
107
108 return (
109 <div>
110 <div>
111 <a onClick={() => setPostId(-1)} href="#">
112 Back
113 </a>
114 </div>
115 {!postId || status === 'pending' ? (
116 'Loading...'
117 ) : status === 'error' ? (
118 <span>Error: {error.message}</span>
119 ) : (
120 <>
121 <h1>{data.title}</h1>
122 <div>
123 <p>{data.body}</p>
124 </div>
125 <div>{isFetching ? 'Background Updating...' : ' '}</div>
126 </>
127 )}
128 </div>
129 )
130}
131
132function App() {
133 const [postId, setPostId] = React.useState(-1)

Callers

nothing calls this directly

Calls 1

usePostFunction · 0.70

Tested by

no test coverage detected