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

Function Post

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

Source from the content-addressed store, hash-verified

69}
70
71function Post({
72 postId,
73 setPostId,
74}: {
75 postId: number
76 setPostId: React.Dispatch<React.SetStateAction<number>>
77}) {
78 const { status, data, error, isFetching } = useQuery(
79 postsQueries.detail(postId),
80 )
81
82 return (
83 <div>
84 <div>
85 <a onClick={() => setPostId(-1)} href="#">
86 Back
87 </a>
88 </div>
89 {status === 'pending' ? (
90 'Loading...'
91 ) : status === 'error' ? (
92 <span>Error: {error.message}</span>
93 ) : (
94 <>
95 <h1>{data.title}</h1>
96 <div>
97 <p>{data.body}</p>
98 </div>
99 <div>{isFetching ? 'Background Updating...' : ' '}</div>
100 </>
101 )}
102 </div>
103 )
104}
105
106function App() {
107 const [postId, setPostId] = React.useState(-1)

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected