import React, { useState, useEffect } from 'react'
const App = () => {
const [countries, setCountries] = useState([])
useEffect(() => {
const getCountries = async () => {
const response = await fetch('https://restcountries.eu/rest/v2/all?fields=name')
const responseJson = await response.json()
console.log(responseJson)
setCountries(responseJson)
}
getCountries()
}, [])
return (
<div>
<ul>
{countries.map((country, index) => {
return (
<li key={index}>
{country.name}
</li>
)
})}
</ul>
</div>
)
}
export default App
const App = () => {
const [countries, setCountries] = useState([])
useEffect(() => {
const getCountries = async () => {
const response = await fetch('https://restcountries.eu/rest/v2/all?fields=name')
const responseJson = await response.json()
console.log(responseJson)
setCountries(responseJson)
}
getCountries()
}, [])
return (
<div>
<ul>
{countries.map((country, index) => {
return (
<li key={index}>
{country.name}
</li>
)
})}
</ul>
</div>
)
}
export default App
No comments:
Post a Comment