esakki-countries
Version:
This is the package to fetch the country details
2 lines (1 loc) • 319 B
JavaScript
import{useState as t,useEffect as r}from'react';const o=o=>{const[c,n]=t([]),[a,e]=t(!1),[s,i]=t('');return r((()=>{(async()=>{e(!0);try{const t=await fetch(`https://restcountries.com/v3.1/name/${o}`),r=await t.json();n(r)}catch(t){i(t)}finally{e(!1)}})()}),[o]),{country:c,loading:a,error:s}};export{o as useCountry};