์ ์ฒด์ ์ธ ํ๋ก์ธ์ค์ ์ง์คํ์!
์ ๋นํธ์ฝ์ธ ์ํ๋๋ฐ์....
์ค๋์ ๋๊ผฌ์ค๊ณผ ํจ๊ป ๋นํธ์ฝ์ธ tracker์ ๋ง๋ค๊ธฐ๋กํ๋ค.
์ผ๋จ ๋ง๋ค์ด๋ณด์์๋๋ค..
import { useEffect, useState } from "react";
function App() {
const [loading, setLoading] = useState(true);
const [coins, setCoins] = useState([]);
const [myMoney, setMyMoney] = useState([]);
// ์ฌ๊ธฐ๋ฅผ ๋น์ด์๋ ๋ฐฐ์ด๋ก ๋์ด์ undefied๊ฐ ๋์ง์๋๋กํ๋ค.
useEffect(() => {
fetch("https://api.coinpaprika.com/v1/tickers")
.then((response) => response.json())
.then((json) => setCoins(json));
setLoading(false);
}, []); //์ด ๋ถ๋ถ์ด ๋น ๋ฐฐ์ด์ด๋ฉด ์ด ์ฝ๋๋ ํ๋ฒ๋ง ๋์ํจ
function onChange(event) {
setMyMoney(event.target.value);
}
return (
<div>
<h1>The Coins!{loading ? "" : `(${coins.length})`}</h1>
<input
onChange={onChange}
value={myMoney}
type="number"
placeholder="Please Write your USD"
></input>
{loading ? (
<strong>loading...</strong>
) : (
<select>
{coins.map((coin) => (
<option>
{coin.rank} ::
{coin.name} ({coin.symbol}) <br />(
{coin.total_supply}{" "}
: $
{coin.quotes.USD.price
}
)USD /
{myMoney
? (myMoney / coin.quotes.USD.price)
: ""}
</option>
))}
;
</select>
)}
</div>
);
}
export default App;
์ผ๋จ ์ด๋ ๊ฒ ๋ง๋ค์๋๋ฐ input์ ๋นํธ์ฝ์ธ์ผ๋ก ๋ฐ๊พธ๊ณ ์ถ์ ๋ฌ๋ฌ์ ๊ฐ์ ๋ฃ์ ์ ์๋ ๊ธฐ๋ฅ์ ๋ง๋ค๋ผ๊ณ ํด์ ์๊ฐํด๋ดค๋๋ฐ ..
๋๋ฌด์ง ๋๋ฌด์ง!! ์ด๋ป๊ฒ ๋ฃ์ด์ผํ ์ง ๊ฐ์ด ์กํ์ง ์์๋ค..
ํญ์ ์๋์ ์ผ๋ก ํ๋ฉด์ ๋ง๋ค์ด์์ผ๊น..
๊ฒฐ๊ตญ ๋ค๋ฅธ ์๊ฐ์๊บผ ์นดํผํจ
๊ทผ๋ฐ ์ด๋ ๊ฒ ๋ง๋ค๋ค๋ณด๋ ์์ซ์ ๊ณผ ์๋ฆฟ์๊ฐ ๋๋ฌด ๊ฑฐ์ฌ๋ ค์ ์์ซ์ ์ ๋ฆฌํ๊ธฐ๋ก ํ๋ค.
import { useEffect, useState } from "react";
function App() {
const [loading, setLoading] = useState(true);
const [coins, setCoins] = useState([]);
const [myMoney, setMyMoney] = useState([]);
//์ฌ๊ธฐ๋ฅผ ๋น์ด์๋ ๋ฐฐ์ด๋ก ๋์ด์ undefied๊ฐ ๋์ง์๋๋กํ๋ค.
useEffect(() => {
fetch("https://api.coinpaprika.com/v1/tickers")
.then((response) => response.json())
.then((json) => setCoins(json));
setLoading(false);
}, []); //์ด ๋ถ๋ถ์ด ๋น ๋ฐฐ์ด์ด๋ฉด ์ด ์ฝ๋๋ ํ๋ฒ๋ง ๋์ํจ
function onChange(event) {
setMyMoney(event.target.value);
}
return (
<div>
<h1>The Coins!{loading ? "" : `(${coins.length})`}</h1>
<input
onChange={onChange}
value={myMoney}
type="number"
placeholder="Please Write your USD"
></input>
{loading ? (
<strong>loading...</strong>
) : (
<select>
{coins.map((coin) => (
<option>
{coin.rank} ::
{coin.name} ({coin.symbol}) <br />(
{coin.total_supply
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}{" "}
: $
{coin.quotes.USD.price
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
)USD /
{myMoney
? (myMoney / coin.quotes.USD.price)
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
: ""}
</option>
))}
;
</select>
)}
</div>
);
}
export default App;
์ผ๋จ ์ด๋ฐ์์ผ๋ก
{coin.quotes.USD.price
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
์ด๋ฐ์์ผ๋ก {}์์ ์์ซ์ ๋์๋ฆฌ ๋ค์๋ ์๋ผ๋ด๊ณ ์ฒ๋จ์๋ก ๋จ์๋ฅผ ๋์๋ค.
.toFixed() ์ด๋ถ๋ถ์ด ์์ซ์ ๋ช๋ฒ์งธ ์๋ฆฌ๊น์ง ์๋ผ๋ผ์ง
.toString() ์ด๊ฑด ,ํ๋ฅผ ์ฐ๊ธฐ์ํด์ string ํ์
์ผ๋ก ๋ณํ
.replace(/\B(?=(\d{3})+(?!\d))/g, ",") 3์๋ฆฌ๋ง๋ค ๋ฐ์ํ๋ฅผ ๊ธฐ๋ฅ์ด๋ค.
์ถ๊ฐ๋ก mymoney๊ฐ ๋น ๊ฐ์ผ ๋ mymoney์ ๊ฐ์ด 0.0์ผ๋ก ํ๊ธฐ๋๊ณ ์์๋๋ฐ mymoney์ ๊ฐ์ด ์์ ๋ ๋น ๋ฌธ์์ด๋ก ์ถ๋ ฅ๋๋๋ก if๋ฌธ์ ์ถ๊ฐํ๋ค.
์ด ๋ชจ๋ ๋ถ๋ถ์ ์์ ํ๋๋ฐ loadingํ๋ฉด์ด ์ ์์ ์ผ๋ก ๊ตฌ๋๋์ง ์์์
useEffect๋ถ๋ถ์ ๋ค์ ๋ณด๋๊น ๊ดํธ๋ฅผ ์๋ชป๋ซ์์ ๊ทธ๋ฐ๊ฑฐ์๋ค๋ฉฐ~ ๋จธ์ฑ
ใ
ใ
import { useEffect, useState } from "react";
function App() {
const [loading, setLoading] = useState(true);
const [coins, setCoins] = useState([]);
const [myMoney, setMyMoney] = useState([]);
// ์ฌ๊ธฐ๋ฅผ ๋น์ด์๋ ๋ฐฐ์ด๋ก ๋์ด์ undefied๊ฐ ๋์ง์๋๋กํ๋ค.
// useEffect(() => {
// fetch("https://api.coinpaprika.com/v1/tickers")
// .then((response) => response.json())
// .then((json) => setCoins(json));
// setLoading(false);
// }, []); //์ด ๋ถ๋ถ์ด ๋น ๋ฐฐ์ด์ด๋ฉด ์ด ์ฝ๋๋ ํ๋ฒ๋ง ๋์ํจ
useEffect(() => {
fetch("https://api.coinpaprika.com/v1/tickers")
.then((response) => response.json())
.then((json) => {
setCoins(json);
setLoading(false); //๊ดํธ๊ฐ ์ ์์ ์ผ๋ก ์๋ซํ์ setLoading์ด ์ ์์ ์ผ๋ก ๊ตฌํ๋์ง ์์์ ์ค๋ฅ ๋ฐ์ํจ
});
}, []);
function onChange(event) {
setMyMoney(event.target.value);
}
return (
<div>
<h1>The Coins!{loading ? "" : `(${coins.length})`}</h1>
<input
onChange={onChange}
value={myMoney}
type="number"
placeholder="Please Write your USD"
></input>
{loading ? (
<strong>loading...</strong>
) : (
<select>
{coins.map((coin) => (
<option>
{coin.rank} ::
{coin.name} ({coin.symbol}) <br />(
{coin.total_supply
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}{" "}
: $
{coin.quotes.USD.price
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
)USD /
{myMoney
? (myMoney / coin.quotes.USD.price)
.toFixed(2)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
: ""}
</option>
))}
;
</select>
)}
</div>
);
}
export default App;
https://melonplaymods.com/2023/06/11/furniture-mod-for-melon-playground-2/
https://melonplaymods.com/2023/06/10/one-piece-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/dump-for-melon-playground-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/radioactive-gun-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/tree-without-leaves-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/scp-foundation-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/super-marie-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/t90-a-tank-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/business-class-sedan-lorder-sidan-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/secret-laboratory-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/flower-tail-pigeon-machinery-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/rocket-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/bedroom-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/masquerade-knight-one-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/devil-fruit-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/three-trucks-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/drinks-pack-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/arta-with-reactive-armor-mod-for-melon-playground/
https://melonplaymods.com/2023/06/11/police-car-with-glow-mod-for-melon-playground/
https://melonplaymods.com/2023/06/10/swat-mod-for-melon-playground/