i want to call a getName function which takes a game.set(Integer) and returns a String.
This string i want to set inside the text element.
The function is working perfectly, I printed the results before returning.
Now, after importing the function import { getName } from '../SetsAPI';, the result I get after calling the function is always undefined.
Function call:
import { getName } from '../SetsAPI';
...
    <View style={styles.row}>
      <Text style={styles.text}>Game: </Text>
          <View style={styles.questionAmount}>
               <Text>{getName(game.set)}</Text>
          </View>
     </View>
Function:
 export const getName = (setId)=>{
    console.log("setId: " + setId)
    setsRef
    .doc(setId)
    .get()
    .then((doc) => {
      if (doc.exists) {
        console.log("document name: " + doc.data().name)
        return doc.data().name;
      } else {
        console.log("No such document!");
      }
  })
  }
Why does this happen? And how can I prevent it? Thank you!
 
    