import { useEffect, useState } from "react";
function App() {
const [loading, setLoading] = useState(true);
const [coins, setCoins] = useState([])
useEffect(() => {
fetch("https://api.coinpaprika.com/v1/tickers")
.then((response) => response.json())
.then((json) => {
setCoins(json);
setLoading(false);
});
}, []);
return (
<div>
<h1>The Coins! ({coins.length})</h1>
{loading ? <strong>Loading...</strong> : null}
<select>
{coins.map((coins) => (
<option>
{coins.name} ({coins.symbol}): ${coins.quotes.USD.price} USD
</option>
))}
</select>
</div>
);
}
export default App;
JavaScript
복사