UNPKG

react-countries-details

Version:
2 lines (1 loc) 345 B
import{useState as t,useEffect as o}from'react';const n=n=>{const[r,c]=t([]),[a,e]=t(!1),[s,i]=t();return o((()=>{(async()=>{try{e(!0);const t=await fetch(`https://restcountries.com/v3.1/name/${n}`),o=await t.json();c(o)}catch(t){i('The country is not found !!')}finally{e(!1)}})()}),[n]),{loading:a,error:s,country:r}};export{n as useCountry};