| 97 | } |
| 98 | |
| 99 | function Post({ |
| 100 | postId, |
| 101 | setPostId, |
| 102 | }: { |
| 103 | postId: number |
| 104 | setPostId: React.Dispatch<React.SetStateAction<number>> |
| 105 | }) { |
| 106 | const { status, data, error, isFetching } = usePost(postId) |
| 107 | |
| 108 | return ( |
| 109 | <div> |
| 110 | <div> |
| 111 | <a onClick={() => setPostId(-1)} href="#"> |
| 112 | Back |
| 113 | </a> |
| 114 | </div> |
| 115 | {!postId || status === 'pending' ? ( |
| 116 | 'Loading...' |
| 117 | ) : status === 'error' ? ( |
| 118 | <span>Error: {error.message}</span> |
| 119 | ) : ( |
| 120 | <> |
| 121 | <h1>{data.title}</h1> |
| 122 | <div> |
| 123 | <p>{data.body}</p> |
| 124 | </div> |
| 125 | <div>{isFetching ? 'Background Updating...' : ' '}</div> |
| 126 | </> |
| 127 | )} |
| 128 | </div> |
| 129 | ) |
| 130 | } |
| 131 | |
| 132 | function App() { |
| 133 | const [postId, setPostId] = React.useState(-1) |