1

I want to see the link to my image in the imageUrl variable.

When I log sampleImage, I see JSON-like data and I can see a link in this data's i section.

But when I log imageUrl, it returns undefined.

render() {
    const uid = '12345';     
    const imageRef = firebase.storage().ref(uid).child(uid);
    const sampleImage = imageRef.getDownloadURL().then();
    const imageUrl = sampleImage.i;
    console.log(sampleImage);    
    console.log(imageUrl);
    return (
        <View>
            <Image style={{ width: 55, height: 55 }} source={{ uri: null }} />
         </View>
    );
}
}

1 Answer 1

2

Getting an image is a network request so it takes a little while. If you want to log the image (and you don't use async/await) then you have to do it inside the .then()

const sampleImage = imageRef.getDownloadURL().then(result => console.log(result));

Rather than doing all of this in the render method, do it when the component mounts and store the URL in state. That way you can just reference the state object in your render method.

Sign up to request clarification or add additional context in comments.

2 Comments

Hello! Yes you are amazing, finally i can see my link in log but now problem is i can't set it to a variable for image uri.
Use state. Set state inside the then and then reference state in your image src.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.