import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
const CountryDetail = () => {
const {countryname}=useParams();
const[countrydet,setCountry]=useState([]);
useEffect(()=>{
const url=`https://restcountries.com/v3.1/name/${countryname}`;
fetch(url)
.then(res=>res.json())
.then(data=>setCountry(data))
},[])
return (
<div style={{textAlign: 'center'}}>
<h3>This is country details : {countryname}</h3>
<h4>{countrydet.name.common}</h4>
<h4>{countrydet.continents}</h4>
</div>
);
};
export default CountryDetail;
but there is a element in object {"name":{"common":"Bangladesh","official":"People's Republic of Bangladesh","nativeName":{"ben":{"official":"বাংলাদেশ গণপ্রজাতন্ত্রী","common":"বাংলাদেশ"}}}