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