getUD = (v) => {
    firebase
      .firestore()
      .collection("users")
      .doc(v)
      .get()
      .then((doc) => {
        let x = doc.data().name;
        console.log(x);
      });
    return "x";
  };
            Asked
            
        
        
            Active
            
        
            Viewed 41 times
        
    -1
            
            
         
    
    
        brk
        
- 48,835
- 10
- 56
- 78
- 
                    You can only return _a promise to the value of `x`_, not the value itself. – CherryDT Aug 12 '20 at 09:57
2 Answers
0
            
            
        Try like this
getUD = (v) => {
  return firebase
    .firestore()
    .collection("users")
    .doc(v)
    .get()
    .then((doc) => {
      return doc.data().name;
    });
}; 
    
    
        brk
        
- 48,835
- 10
- 56
- 78
- 
                    @KorenHamra this is because the `getUD` function is itself asynchronous and returns a promise. You need to use `then()` or `async/await` when you call it. – Renaud Tarnec Aug 12 '20 at 12:39
- 
                    
0
            
            
        getUD = async (v) => {
  const doc = await firebase
    .firestore()
    .collection("users")
    .doc(v)
    .get();
  return doc.data().name;
};
getUD = (v) => {
  return firebase
    .firestore()
    .collection("users")
    .doc(v)
    .get()
    .then((doc) => {
      return doc.data().name;
    });
};You can simply use async/ await or return from your then.
 
    
    
        Nicolae Maties
        
- 2,476
- 1
- 16
- 26
