2

In my app I want the user name to be displayed after user logins for that i have used the Uid but I am not recieving data from firebase

Using RN>57.8

this is my code:

componentDidMount(){ firebase.database() .ref('users/'+this.state.uid) .on('value',(snapshot)=>{ const name1 = snapshot.val().name; alert(name1) }) } 

and

componentDidMount(){ firebase.database() .ref(`users/${this.state.uid}`) .on('value',(snapshot)=>{ const name1 = snapshot.val().name; alert(name1) }) } 

I want to show alert message with the name of the user but it is not working whereas if i write the path directly as shown below i am able to get the alert

Example:

.ref('users/ALM5456N3NNN35HFR56L') 

1 Answer 1

2

Use it like this to get the name

firebase.database() .ref(`users/${this.state.uid}`).on('value',(snapshot)=>{ console.log(snapshot.val()); }) 
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your time i tried this just now i got alert null
I have modified the answer try doing it like this.
i tried no alert showing and getting warning possible unhandled promise rejection (id:0):typeError:null is not an object (evaluating 'userData.name')
I have modified my answer. Console like this and check what are you getting in this.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.