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