I wanna display the data that I have in my state in a map I managed to get both latitude and longitude in my state the problem is whenever try to map trough the state I always get it's not a function error here's parts of my code and the data that I have in the state:
const [countriesData, setCountriesData] = useState({});
useEffect(() => {
const fetchAPI = async () => {
setCountriesData(await fetchDataCountries());
};
fetchAPI();
}, [setCountriesData]);
console.log(countriesData);
and mapping through it like this:
{countriesData.map((data)=>(
<Marker latitude={data.countriesData.latitude}
longitude={data.countriesData.longitude}/>
))}
the fetch api function:
export const fetchDataCountries = async () => {
try {
const data = await axios.get(url);
const newData = data.data;
const modfiedData = newData.map((countryData) => {
return countryData.coordinates;
});
return modfiedData;
} catch (error) {
console.log(error);
}
};