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

Function Post

examples/preact/basic/src/index.tsx:67–100  ·  view source on GitHub ↗
({
  postId,
  setPostId,
}: {
  postId: number
  setPostId: (postId: number) => void
})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected