pull/326/merge
Jaylou Rasonabe 7 months ago committed by GitHub
commit e0d3276e14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -29,17 +29,27 @@ import React, { useState, useEffect } from 'react'
import axios from 'axios' import axios from 'axios'
import ReactDOM, { findDOMNode } from 'react-dom' import ReactDOM, { findDOMNode } from 'react-dom'
const Country = ({ country: { name, flag, population } }) => { const Country = ({ country: {
name: {
common: country_name
},
flags: {
png: flag_png,
alt: flag_alt
},
population
}}) => {
return ( return (
<div className='country'> <div className='country'>
<div className='country_flag'> <div className='country-flag'>
<img src={flag} alt={name} /> <img src={flag_png} alt={flag_alt}/>
</div> </div>
<h3 className='country_name'>{name.toUpperCase()}</h3> <h3 className='country-name'>{country_name}</h3>
<div class='country_text'> <div className='country-details'>
<p> <p>
<span>Population: </span> <span>
{population} Population: {population.toLocaleString()}
</span>
</p> </p>
</div> </div>
</div> </div>
@ -47,21 +57,21 @@ const Country = ({ country: { name, flag, population } }) => {
} }
const App = (props) => { const App = (props) => {
// setting initial state and method to update state
const [data, setData] = useState([]) const [data, setData] = useState([])
useEffect(() => { useEffect(() => {
fetchData() fetchData();
}, []) }, [])
const fetchData = async () => { const fetchData = async () => {
const url = 'https://restcountries.eu/rest/v2/all' const url = 'https://restcountries.com/v3.1/all'
try { try {
const response = await fetch(url) const response = await fetch(url);
const data = await response.json() const data = await response.json();
setData(data) setData(data);
console.log(data);
} catch (error) { } catch (error) {
console.log(error) console.log(error);
} }
} }
@ -73,7 +83,7 @@ const App = (props) => {
<p>There are {data.length} countries in the api</p> <p>There are {data.length} countries in the api</p>
<div className='countries-wrapper'> <div className='countries-wrapper'>
{data.map((country) => ( {data.map((country) => (
<Country country={country} /> <Country country={country}/>
))} ))}
</div> </div>
</div> </div>

Loading…
Cancel
Save