I know this has been asked a gazillion times. I've asked it myself. Specifically to the code below I don't know why this doesn't resolve.
const householdPics = (data, props) => {
let refImg;
async function refDetails() {
let urlResult;
const ref = await props.firebase.storageRef(`images/${data.profilePic}`);
return urlResult = new Promise((resolve, reject) => {
ref.getDownloadURL()
.then(url => resolve(url))
.catch(e => reject(e))
})
}
if (!data.profilePic || data.profilePic == 'NULL') {
refImg = require("../../assets/img/empty-avatar.png");
} else {
refImg = refDetails();
}
I'm sure I'm over complicating this, I've been at it so long I'm all confused myself.
I would expect refImg = refDetails();
to resolve to a url.
if I console.log urlResult
I get an img url from firebase.
However when I use refImg in another block of code:
src appears as Object Promise
I also tried:
async function refDetails() {
const ref = await props.firebase.storageRef(`images/${data.profilePic}`);
const refUrl = await ref.getDownloadURL();
return refUrl;
}
Here is another attempt I've tried after reading up more on this. Still failing :(
let refImg;
function refDetails() {
const ref = props.firebase.storageRef(`images/${data.profilePic}`);
const imgUrl = ref.getDownloadURL()
return imgUrl.then(url => {return url})
}
if (!data.profilePic || data.profilePic == 'NULL') {
refImg = require("../../assets/img/empty-avatar.png");
} else {
const resultImg = refDetails();;
refImg = resultImg;
}
How can I pass the return value of ref.getDownloadURL() to refImg?