기록
리액트8 코인api 가져와서 출력하기 useEffect fecth map 본문
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!{ loading ? "" : `(${coins.length})`}</h1>
{loading ? <strong>Loading...</strong> :
<ul>
{coins.map((coin) => (
<li key={coin.rank}>
{coin.name} ({coin.symbol}) : {coin.quotes.USD.price}
</li>
))}
</ul>
}
</div>
)
}
export default App;
'REACT' 카테고리의 다른 글
리액트10 gh-page를 이용하여 github pages에 올리기 (0) | 2023.09.15 |
---|---|
리액트9 영화사이트 만들기/React Router (react-router-dom) (0) | 2023.09.14 |
리액트7 toDoList만들기 /배열, map() (0) | 2023.09.13 |
리액트6 useEffect() / cleanUp function (0) | 2023.09.12 |
리액트5 create-react-app 설치 및 css적용 (0) | 2023.09.12 |
Comments