-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
37 lines (30 loc) · 890 Bytes
/
App.js
File metadata and controls
37 lines (30 loc) · 890 Bytes
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
import React, { Component } from 'react';
import { Cards, Charts, CountryPicker } from './components';
import { fetchData } from './api';
class App extends Component {
state = {
data: {},
country: '',
}
async componentDidMount() {
const fetchedData = await fetchData();
this.setState({ data: fetchedData });
}
handleCountryChange = async (country) => {
const fetchedData = await fetchData(country);
this.setState({ data: fetchedData, country: country });
}
render() {
const { data, country } = this.state;
return (
<React.Fragment>
<div className="container mx-auto px-4 p-5 pt-10">
<Cards data={ data } />
<CountryPicker handleCountryChange={ this.handleCountryChange } />
<Charts data={ data } country={ country } />
</div>
</React.Fragment>
)
}
}
export default App;