Hi guys i want to add al countries to state but problem is state only returning one country
const [country, getCountry] = useState([]); useEffect(() => {
axios
.request("https://restcountries.com/v3.1/all")
.then((response) => {
response.data.forEach((element) => {
getCountry(element.name.official);
});
})
.catch(function (error) {
console.error(error);
}); }, []);
>Solution :
You are setting one by one and the last one will be final state so you may do as following:
.then((response) => {
getCountry(response.data.map((element) => element.name.official))
})