Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithSouma committed Nov 3, 2020
1 parent 77630fc commit ada576c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class App extends Component {
};
async componentDidMount() {
const fetchedData = await fetchData();
this.setState({ data: fetchedData });
this.setState({ data: fetchedData || {} });
}

handleCountryChange = async (country) => {
const fetchedData = await fetchData(country);
this.setState({ data: fetchedData, country: country });
this.setState({ data: fetchedData || {}, country: country || [] });
};

render() {
const { data, country } = this.state;
return (
<div className={styles.container}>
<img className={styles.image} src={coronaImage} alt="Covid-19"/>
<img className={styles.image} src={coronaImage} alt="Covid-19" />
<Cards data={data} />
<CountryPicker handleCountryChange={this.handleCountryChange} />
<Chart data={data} country={country} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function Chart({ data: { confirmed, recovered, deaths }, country }) {

useEffect(() => {
const fetchApi = async () => {
setDailyData(await fetchDailyData());
setDailyData((await fetchDailyData()) || []);
};

fetchApi();
},[]);
}, []);

const lineChart = dailyData.length ? (
<Line
Expand Down

0 comments on commit ada576c

Please sign in to comment.