Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

기록

리액트8 코인api 가져와서 출력하기 useEffect fecth map 본문

REACT

리액트8 코인api 가져와서 출력하기 useEffect fecth map

9400 2023. 9. 13. 11:37
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;
Comments