({
postId,
setPostId,
}: {
postId: number
setPostId: React.Dispatch<React.SetStateAction<number>>
})
| 110 | } |
| 111 | |
| 112 | function Post({ |
| 113 | postId, |
| 114 | setPostId, |
| 115 | }: { |
| 116 | postId: number |
| 117 | setPostId: React.Dispatch<React.SetStateAction<number>> |
| 118 | }) { |
| 119 | // You can even leave out the queryFn and just go straight into options |
| 120 | const { status, data, error, isFetching } = useQuery<Post>({ |
| 121 | queryKey: [`/posts/${postId}`], |
| 122 | enabled: !!postId, |
| 123 | }) |
| 124 | |
| 125 | return ( |
| 126 | <div> |
| 127 | <div> |
| 128 | <a onClick={() => setPostId(-1)} href="#"> |
| 129 | Back |
| 130 | </a> |
| 131 | </div> |
| 132 | {!postId || status === 'pending' ? ( |
| 133 | 'Loading...' |
| 134 | ) : status === 'error' ? ( |
| 135 | <span>Error: {error.message}</span> |
| 136 | ) : ( |
| 137 | <> |
| 138 | <h1>{data.title}</h1> |
| 139 | <div> |
| 140 | <p>{data.body}</p> |
| 141 | </div> |
| 142 | <div>{isFetching ? 'Background Updating...' : ' '}</div> |
| 143 | </> |
| 144 | )} |
| 145 | </div> |
| 146 | ) |
| 147 | } |
| 148 | |
| 149 | const rootElement = document.getElementById('root') |
| 150 | if (!rootElement) throw new Error('Missing #root element') |
nothing calls this directly
no test coverage detected