how can I render the data coming from my firestore database in react native?
below is my code that only pushes the data in an array but I don't know how to use it in a Card. I tried to use Flatlist but failed.
As of now whenever I tried to print the data in the console it looks like this:
Array [ "VD GOT JEALOUS", "Sample Content", ]
I want that array to be render in Card or Text component
state = {
content: []
}
componentWillMount(){
/* similar to mounted in vue */
this.retrieveAnnouncement()
}
retrieveAnnouncement = () => {
/* retrieve announcements */
firebase.firestore().collection("announcement").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
this.state.content.push(doc.data().CONTENT);
}).catch(err => console.log(err));
});
};
render() {
return (
<View>
<Button onPress={this.samplePrint} title="Print"></Button>
</View>
)
}
You can change your firebase code:
After this in render method you can use the content array.
Hope this will help to solve your problem.