all feature done.

pull/161/head
ardaninsaturnu 3 years ago
parent 3275575433
commit f555e42669

@ -15,46 +15,46 @@ class App extends Component {
console.log('I am componentDidMount and I will be last to run.') console.log('I am componentDidMount and I will be last to run.')
const API_URL = 'https://restcountries.eu/rest/v2/all' const API_URL = 'https://restcountries.eu/rest/v2/all'
fetch(API_URL) fetch(API_URL)
.then((response) => { .then((response) => {
return response.json() return response.json()
}) })
.then((data) => { .then((data) => {
console.log(data) console.log(data)
this.setState({ this.setState({
data, data,
})
})
.catch((error) => {
console.log(error)
}) })
})
.catch((error) => {
console.log(error)
})
} }
renderCountries = () => { renderCountries = () => {
return this.state.data.map((country) => { return this.state.data.map((country) => {
return ( return (
<div>
<div>
{' '}
<img src={country.flag} alt={country.name} />{' '}
</div>
<div> <div>
<h1>{country.name}</h1> <div>
<p>Population: {country.population}</p> {' '}
<img src={country.flag} alt={country.name} />{' '}
</div>
<div>
<h1>{country.name}</h1>
<p>Population: {country.population}</p>
</div>
</div> </div>
</div>
) )
}) })
} }
render() { render() {
return ( return (
<div className='App'> <div className='App'>
<h1>React Component Life Cycle</h1> <h1>React Component Life Cycle</h1>
<h1>Calling API</h1> <h1>Calling API</h1>
<div> <div>
<p>There are {this.state.data.length} countries in the api</p> <p>There are {this.state.data.length} countries in the api</p>
<div className='countries-wrapper'>{this.renderCountries()}</div> <div className='countries-wrapper'>{this.renderCountries()}</div>
</div>
</div> </div>
</div>
) )
} }
} }

Loading…
Cancel
Save