티스토리 뷰

React

coin making

이채야채 2021. 11. 28. 13:22

노카드코더 보면서 리액트와 익숙해지자

좌절감으로 배움을 늦추지 마라!!

 

import logo from './logo.svg';
import {useState, useEffect} from "react"
import './App.css';

function App() {
  const [loading,setLoading] = useState(true)
  const [coins, setCoins] = useState([])
  const [dollors,setDollors] = useState('')
  const [inverted,setInverted] = useState(true)

  const onChange = (event)=>{
    setDollors(event.target.value)
  }

  const onClick = (event) =>{
    setInverted((current) => !current)
  }

  useEffect(()=>{
    fetch("https://api.coinpaprika.com/v1/tickers")
    .then((res)=>{
      return res.json()
    })
    .then((data)=>setCoins(data))
     setLoading(false)
  },[] )
  return ( //USD->BTC만들기 input만들어서
    <div className="App">
      <h1>The Coins! ({coins.length})</h1>
      {loading ? <strong>Loading...</strong> : null}
      <select>
        {coins.map((coin) =>  
        <option>{coin.name}({coin.symbol}) : ${coin.quotes.USD.price}</option>)}
      </select>
      <input value = {inverted? dollors : dollors*10 } type = "text" onChange = {onChange}>
      </input>
      <button onClick = {onClick}>button</button>
    </div>
  );
}

export default App;//

'React' 카테고리의 다른 글

상태끌어올리기 : 함수를 내려주셈  (0) 2021.12.02
useRef  (0) 2021.11.29
todo list  (0) 2021.11.27
리액트 hook (useState와 useEffect)  (0) 2021.11.23
React  (0) 2021.11.17
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/06   »
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
글 보관함