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

Function Posts

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

Source from the content-addressed store, hash-verified

37}
38
39function Posts({ setPostId }: { setPostId: (postId: string | null) => void }) {
40 const queryClient = useQueryClient()
41 const { status, data, error, isFetching } = useQuery(postsQueries.list())
42
43 return (
44 <div>
45 <h1>Posts</h1>
46 <div>
47 {status === 'pending' ? (
48 'Loading...'
49 ) : status === 'error' ? (
50 <span>Error: {error.message}</span>
51 ) : (
52 <>
53 <div>
54 {data.map((post) => (
55 <p key={post.id}>
56 <a
57 onClick={() => setPostId(post.id)}
58 href="#"
59 style={
60 // We can find the existing query data here to show bold links for
61 // ones that are cached
62 queryClient.getQueryData(
63 postsQueries.detail(post.id).queryKey,
64 )
65 ? {
66 fontWeight: 'bold',
67 color: 'green',
68 }
69 : {}
70 }
71 >
72 {post.title}
73 </a>
74 </p>
75 ))}
76 </div>
77 <div>{isFetching ? 'Background Updating...' : ' '}</div>
78 </>
79 )}
80 </div>
81 </div>
82 )
83}
84
85function Post({
86 postId,

Callers

nothing calls this directly

Calls 3

useQueryClientFunction · 0.90
useQueryFunction · 0.90
getQueryDataMethod · 0.45

Tested by

no test coverage detected