({ setPostId }: { setPostId: (postId: number) => void })
| 19 | }) |
| 20 | |
| 21 | function Posts({ setPostId }: { setPostId: (postId: number) => void }) { |
| 22 | const queryClient = useQueryClient() |
| 23 | const { status, data, error, isFetching } = useQuery(postsQueries.list()) |
| 24 | |
| 25 | return ( |
| 26 | <div> |
| 27 | <h1>Posts</h1> |
| 28 | <div> |
| 29 | {status === 'pending' ? ( |
| 30 | 'Loading...' |
| 31 | ) : status === 'error' ? ( |
| 32 | <span>Error: {error.message}</span> |
| 33 | ) : ( |
| 34 | <> |
| 35 | <div> |
| 36 | {data.map((post) => ( |
| 37 | <p key={post.id}> |
| 38 | <a |
| 39 | onClick={() => setPostId(post.id)} |
| 40 | href="#" |
| 41 | style={ |
| 42 | // We can access the query data here to show bold links for |
| 43 | // ones that are cached |
| 44 | queryClient.getQueryData( |
| 45 | postsQueries.detail(post.id).queryKey, |
| 46 | ) |
| 47 | ? { |
| 48 | fontWeight: 'bold', |
| 49 | color: 'green', |
| 50 | } |
| 51 | : {} |
| 52 | } |
| 53 | > |
| 54 | {post.title} |
| 55 | </a> |
| 56 | </p> |
| 57 | ))} |
| 58 | </div> |
| 59 | <div>{isFetching ? 'Background Updating...' : ' '}</div> |
| 60 | </> |
| 61 | )} |
| 62 | </div> |
| 63 | </div> |
| 64 | ) |
| 65 | } |
| 66 | |
| 67 | function Post({ |
| 68 | postId, |
nothing calls this directly
no test coverage detected