I am trying to loop through an array of values returned asyncronously from an API, and within that loop I want to call another function that returns a promise. I cannot get the second promise to be evaluated within the loop. How do I do this??
async componentDidMount(){
const resolvedCampgrounds = await this.returnThoseValues('getListings','/world')
resolvedCampgrounds.forEach(async feature=> {
if (feature['mapOn'].toUpperCase()==='TRUE'){
await coordinateData.push({
"key": feature['id'],
"Address": feature['street_address'] + feature['zip_code'],
"image": jpg,
"position": CodeAddress(feature['street_address'] + feature['zip_code'],this.props.google).then(value => {return value})
})
}
})
set_state(coordinateData);
CodeAddress() returns a resolved promise, the result of which I attempt to access via .then().The only way I have been able to accomplish this so far is to call set_state within the loop on each object individually (instead of array.push-ing), but that does not suffice as I need to 'bulk push' rather than changing state every time.