1

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:

enter image description here

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>
);
}
2
  • 1
    What's displayed currently, and what's logged if you console.log(this.state.datums) in your render method? Commented May 21, 2019 at 11:00
  • Do you have the right to read the datas? Check your rules, it might forbid you to read some datas Commented May 21, 2019 at 12:11

1 Answer 1

1

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})
      })
   }
Sign up to request clarification or add additional context in comments.

Comments

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.