I have this link https://api.covid19api.com/countries, which holds the "Country", "Slug", and "ISO2" of several countries. I want to display, only the "Country" value in tag.I wrote the following code
function App() {
const [countries,setCountries] = React.useState();
React.useEffect(()=>{
async function fetchData(){
const data = fetch('https://api.covid19api.com/countries').then(resp => resp.json());
setCountries(data)
}
fetchData();
},[])
if(!countries){
return(
<h3>Loading.....</h3>
)
}
return (
<div>
{
countries.map(() => <h1>{countries.Country}</h1>)
}
</div>
);
}
export default App;
but, it was giving the following error
TypeError: countries.map is not a function
Could anyone please say the correct way to do it
countries && countries.ma(...). You can do a console.log just before the return at one point countries will be undefined then will later be defined after the API request is done.