I am currently trying to display an image with a map function that goes through a document in my firestore. My firestore document looks like this:
and I have a photo in my firebase storage with the same name as the photo id.
I am planning to use
const ref = firebase.storage().ref(item.photoid);
const url = await ref.getDownloadURL();
with
renderAccordion() {
return this.state.accordionarr.map((item,index) => {
return(
<View key={index}>
<Accordion
onChange={this.onChange}
activeSections={this.state.activeSections}
>
<Accordion.Panel header= {item.name}>
<List>
<List.Item>{item.protein}</List.Item>
<List.Item>{item.carbohydrate}</List.Item>
</List>
</Accordion.Panel>
</Accordion>
</View>
);
});
}
to show the image. However, in order to have "await" I have to make renderAccordion() an async function. But, when I do that, I received an "invariant violation objects are not valid as a react child" error. What is a way to retrieve the image based on my document field of photoid and successfully display it on the screen?
EDIT: I've added a function to set state of each one of my photos
renderAccordion() {
return this.state.accordionarr.map((item,index) => {
let fetchImage
firebase
.storage()
.ref(item.photoid)
.getDownloadURL()
.then((url) => {
let state = {};
state[item.photoid] = url
this.setState(state)
});
return(
<View key={index}>
<Accordion
onChange={this.onChange}
activeSections={this.state.activeSections}
>
<Accordion.Panel header= {item.name}>
<List>
<List.Item>
<Image
style = {styles.sizer}
source = {{uri: this.state[item.photoid]}}
/>
</List.Item>
<List.Item>{item.protein}</List.Item>
<List.Item>{item.carbohydrate}</List.Item>
</List>
</Accordion.Panel>
</Accordion>
</View>
);
});
}
But, now I received an error message that only says [object Object]. What am I doing wrong?