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