Hello everyone
My goal:
Get the result out of a Promise that is fullfilled to use the result in a other piece of code
the results that I get are:
but the expected result is the [[PromiseResult]].
I tried other methods I found on here. but there was one problem I did get the result only to show up in the command.log but when I tried to assign it to a value it looked like it skipped right over the code. I know this sounds like a duplicate posts of a post of How to return the response from an asynchronous call? but I tried it and it didn't work for me.
the check boundries returns a Promise
function getData() {
setLoading(true);
ref.onSnapshot((querySnapshot) => {
const items = [];
querySnapshot.forEach((doc) => {
let itemurl = 'http://leafletjs.com/examples/custom-icons/leaf-green.png';
let item = doc.data()
console.log(checkBoundaries(doc.data().RawData))
itemurl = checkBoundaries(doc.data().RawData)
console.log( itemurl)
item.colorIcon = itemurl;
console.log(item)
items.push(item);
console.log(items)
});
setRuuviTag(items);
setLoading(false);
});
}
but i cant get item.colorIcon to become the promise result
it would help alot if anyone knew a fix for this
Update
async function checkBoundaries(rdata) {
let iconurl;
try {
const response = await PostRawData(rdata)
const data = response.data
if (22.00>data.temperature && data.temperature > 4.00) {
console.log('if')
iconurl = 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-blue.png'
}
else {
console.log('else')
iconurl = 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-red.png'
}
} catch (err) {
console.error(err)
}
console.log(`this is the url ${iconurl}`)
return iconurl
// ...
}
I will now get the things i tried but wont work