import styles from "./App.module.css";
import { useState, useEffect } from "react";
function App() {
const [loading, setLoading] = useState(true);
const [coins, setCoins] = useState([]);
const [money, setMoney] = useState([]);
const onChange = (event) => setMoney(event.target.value);
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>
<input
onChange={onChange}
value={money}
type="number"
placeholder="write your money"
/>
{loading ? (
<strong>Loading...</strong>
) : (
<select>
{coins.map((coin) => (
<option>
{coin.name} ({coin.symbol}) : {money / coin.quotes.USD.price} (
{coin.symbol})
</option>
))}
</select>
)}
</div>
);
}
export default App;
반응형
'FRONT > REACT' 카테고리의 다른 글
[React] Styled Component 사용하기 (0) | 2022.01.19 |
---|---|
[React] async / await (0) | 2022.01.14 |
[React] 리액트로 간단한 투두리스트 만들기 (0) | 2022.01.07 |
[React] Effect Hook- Clean up 함수 (0) | 2022.01.07 |
[React] UseEffect 사용하기(노마드코더 영화 웹서비스 만들기) (0) | 2022.01.06 |