-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
70 lines (60 loc) · 1.83 KB
/
App.js
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
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import './App.css';
import Coin from './Coin';
function App() {
const [coins, setCoins] = useState([]);
//creat a function that gets the values and also it maps through all the data.
const [search, setSearch] = useState('');
//arrow function here we utilize axios
useEffect(() => {
axios
.get(
'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10&page=1&sparkline=false'
)
.then(res => {
setCoins(res.data);
console.log(res.data);
})
.catch(error => console.log(error));
}, []);
//creat handle change function
const handleChange = e => {
setSearch(e.target.value);
};
// creat a function for filter actual coins and display what we type in
const filteredCoins = coins.filter(coin =>
coin.name.toLowerCase().includes(search.toLowerCase())
); // passing coin as a parameter
//adding jsx
return (
<div className='coin-app'>
<div className='coin-search'>
<h1 className='coin-text'>Search a currency</h1>
<form>
<input
className='coin-input'
type='text'
onChange={handleChange}
placeholder='Search'
/>
</form>
</div>
{filteredCoins.map(coin => {
return (
<Coin
key={coin.id}
name={coin.name}
price={coin.current_price}
symbol={coin.symbol}
marketcap={coin.total_volume}
volume={coin.market_cap}
image={coin.image}
priceChange={coin.price_change_percentage_24h}
/>
);
})}
</div>
);
}
export default App;