请你写一段 HTML 代码,在代码中有一段 JSX 代码, 这段代码使用了 React 和 React-Query, 能够发送异步请求访问一个 {API}。 API 是 https://api.exchangerate.host/latest. 并要求将 {API} 返回的数据以列表的形式展示在 HTML 页面上。
时间: 2023-03-13 20:19:51 浏览: 168
在react-router4中进行代码拆分的方法(基于webpack)
<html>
<head>
<title>Exchange Rate</title>
</head>
<body>
<div id="root"></div>
<script type="text/babel"> const { useQuery } = ReactQuery; function App() {
// Fetch the exchange rate data from the API
const { data, isLoading, isError } = useQuery('exchangeRate', () =>
fetch('https://api.exchangerate.host/latest')
.then(res => res.json())
); // Render the exchange rate data in a list
return (
<div>
{isLoading ? (
<div>Loading...</div>
) : isError ? (
<div>Error!</div>
) : (
<ul>
{Object.entries(data?.rates).map(([currency, rate]) => (
<li key={currency}>{currency}: {rate}</li>
))}
</ul>
)}
</div>
);
} ReactDOM.render(<App />, document.getElementById('root'));
</script><script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/react-query@2.2.2/dist/react-query.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.12.5/babel.min.js"></script>
</body>
</html>
阅读全文