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

Function Posts

examples/react/https/src/index.tsx:29–75  ·  view source on GitHub ↗
({
  setPostId,
}: {
  setPostId: React.Dispatch<React.SetStateAction<number>>
})

Source from the content-addressed store, hash-verified

27}
28
29function Posts({
30 setPostId,
31}: {
32 setPostId: React.Dispatch<React.SetStateAction<number>>
33}) {
34 const queryClient = useQueryClient()
35 const { status, data, error, isFetching } = usePosts()
36
37 return (
38 <div>
39 <h1>Posts</h1>
40 <div>
41 {status === 'pending' ? (
42 'Loading...'
43 ) : status === 'error' ? (
44 <span>Error: {error.message}</span>
45 ) : (
46 <>
47 <div>
48 {data.map((post) => (
49 <p key={post.id}>
50 <a
51 onClick={() => setPostId(post.id)}
52 href="#"
53 style={
54 // We can access the query data here to show bold links for
55 // ones that are cached
56 queryClient.getQueryData(['post', post.id])
57 ? {
58 fontWeight: 'bold',
59 color: 'green',
60 }
61 : {}
62 }
63 >
64 {post.title}
65 </a>
66 </p>
67 ))}
68 </div>
69 <div>{isFetching ? 'Background Updating...' : ' '}</div>
70 </>
71 )}
72 </div>
73 </div>
74 )
75}
76
77const getPostById = async (id: number): Promise<Post> => {
78 const response = await fetch(

Callers

nothing calls this directly

Calls 1

usePostsFunction · 0.70

Tested by

no test coverage detected