const devices = [1001, 1002, 1003];
const fetchData = () => {
const fP = devices?.map(async (id) => {
const { data } = await axios.get(`https://www.roads.com/road/ap/roadControl/${id}`, myHeaders);
return data.data;
})
return (fP);
};
const {data} = useQuery ("post", fetchData);
console.log(data);
In this following codes, I'm tring to fetch data from 3 API's using .map() method to change id's end of the API.
but using axios inside map method, i can't fetch the data from the API. if i don,t use .map() method, i can fetch the data without any issues.
something Like that:
const { data } = await axios.get(`https://www.roads.com/road/ap/roadControl/1001`, myHeaders);
If i use .map() method and inside use axois i can't fetch the data. i get undefined.
so how can i fix this issues, any can help me to fix it.
what should i do to fix it?
ThankYou for your trying in advance!.
for my security reason i'm using here false api so you can use to work something valid api.