728x90
반응형
달러를 비트코인 단위로 바꾸기 기능이랑 컴포넌트들 여러개로 분할해봤다.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
import Button from "./Button";
import styles from "./App.module.css";
import {useState,useEffect} from "react";
function Convert({currentMoney}){
const[dollar,setDollar]=useState(0);
const[convert,setConvert]=useState(false);
const onSubmit=(event)=>{
event.preventDefault();
setConvert(true);
}
const onChange=(event)=>{
setDollar(event.target.value);
}
return(
<div>
<form onSubmit={onSubmit}>
<input onChange={onChange} type="text" placeholder="write down dollar" value={dollar} >
</input>
<button>convert</button>
</form>
{convert?<div>
{(dollar/currentMoney).toString()}
</div> : null}
</div>
);
}
function Selection({coins}){
const[selectFin,setSelectFin]=useState(false);
const [currentCoin,setCurrentCoin]=useState("");
const[currentMoney,setCurrentMoney]=useState(0);
const onChange=(event)=>{
setCurrentMoney(event.target.value);
setSelectFin(true);
}
return(
<div>
💜USD to 💜
<select onChange={onChange} >
{coins.map((coin)=>
<option value={coin.quotes.USD.price}>{coin.name}({coin.symbol}):${coin.quotes.USD.price}</option>
)}
</select>
{selectFin?<Convert currentMoney={currentMoney}/>:null}
</div>
);
}
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>:<Selection coins={coins}/>}
</div>
}
export default App;
|
cs |
흠 근데 여기서 문제는
요 부분인데
option 속성에서 value를 비트코인 단위랑 coin.symbol 모두 다 받아오고 싶은데 값 두개를 받아오는게 안됐다.
사실 내가 하고 싶었던건 option에서 value를 두개 받아와서 usd to {currentCoin}이 하고 싶었는데 왜 안되는지 모르겠다...
728x90
반응형
'React' 카테고리의 다른 글
[React] Movie App 만들기(2) - Router을 사용해보자! (0) | 2022.05.06 |
---|---|
[React] Movie App 만들기! (0) | 2022.05.05 |
[React] Coin Tracker 만들기! (0) | 2022.05.04 |
[React] to-do list를 만들어보자! (0) | 2022.05.02 |
[React] clean up function (0) | 2022.05.02 |
댓글