Reputation: 159
I want to display some data from firebase, the problem is that I don't know how to do this after trying many things.
My firebase datbase looks like this:
Now I want to put this data into a calender, so I want only the date from one userID. So I can get only one date, and then use it.
How can I do this?
I now use this:
componentDidMount() {
let userId = firebase.auth().currentUser.uid;
firebase.database().ref('poolog/' + userId ).on('value', (snapshot) => {
this.setState({abc: snapshot.val().childData});
let data = snapshot.val();
let datums = Object.values(data);
this.setState({datums});
});
};
And then I want to render it:
render(){
return(
<View>
<Text>{
this.state.datums
}</Text>
</View>
);
}
Upvotes: 1
Views: 165
Reputation: 234
basically this way i put every single day of an user in an array so you can access any day.And then you can access each day by an index.
componentDidMount(){
var days = []
firebase.database().ref('poolog/' + userId ).once('value', (snap) => {
snap.forEach((data)=>{
days.push({
day:data.key,
availableHours:data.val()
})
})
console.log(days)
//this.setState({datums:days})
})
}
Upvotes: 1