0

I'm trying to learn react native by doing some practical. The problem I have is that I'm not able to use the images I stored in Firebase storage. O just don't know how to do it, so I hope you can help me.

I tried this from the official documentation, but is not working and is saying that await can only be used in async function.

 import storage from '@react-native-firebase/storage';

  const url = await storage()
    .ref('images/profile-1.png')
    .getDownloadURL();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

If you run this code in a context where you can't use await, you can always use then() to accomplish the same:

  storage()
    .ref('images/profile-1.png')
    .getDownloadURL().then((url) => {
      console.log(url);
    });

Just keep in mind that the url is only usable from inside the then callback or from code that you call from there. Trying to use url from elsewhere will result in it not existing, or not being initialized. To learn more about that, also see Why Does Firebase Lose Reference outside the once() Function?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807