title: How to return an array from function react native?
body: <p>This is my first time working with react expo and I want to return the array to create dynamic components based on this array, but my function is not returning. Below is my code:</p>
  
  <pre><code>getgroups = () =&gt; {
    // getting data once
    var arraykey = [];
    var returnarry = [];
    returnarry = firebase
      .database()
      .ref('/groupsOfUser/' + this.state.uid)
      .once('value')
      .then(snapshot =&gt; {
        snapshot.forEach(function(childSnapshot) {
          var childKey = childSnapshot.key;
          console.log(childKey);
          arraykey.push(childKey);
        }); 
        console.log(arraykey); 
        return arraykey;
      }); 
      console.log('return:' + returnarry[0]);
    } 
  }
  </code></pre>
  
  <p><code>returnarry</code> doesn't contain anything. This is the result I am getting when I console log it</p>
  
  <p><strong>return: undefined</strong></p>
  
  <p>Please Help!</p>