I am having a problem that I am apparently to stupid to solve.. I've been trying to solve this problem for to long, and it doesn't seem to crack.
I am fetching data from firebase using the following function:
export function fetchUserData(userID) {
   database.ref('users/' + userID).once('value').then(function(snapshot) {
      if (!snapshot) {
         console.log('An error occured');
      } else {
         let user = {
            first_name: snapshot.val().first_name,
            last_name: snapshot.val().last_name,
         }
         console.log(user);
         return user
      }
   })
}
That function is returning an object, which I am trying to set in state when the component is mounting:
componentWillMount() {
   this.setState({
      userData: fetchUserData('10212667682706511')
   })
}
If I then try to log the userData to the console when the component is mounted, I get undefined, although logging the user from the fetchUserData function, I get the object:
I am assuming something is getting lost when I call fetchUserData and try to store it in state, but I simply don't know how to fix it, so any help would be appreciated.

 
     
    