title: React Native: Write value to variable outside of a inner function
body: <p>i just startet with react native and currently working on a couchdb api for our project. I am doing my rest requests with fecht. But within the inner function i cannot write my responsetext (json) to variable i want to return.</p>
  
  <pre><code>_getDocument(pID)
  {
      var result = "getDocument failed"
  
      var document = "https://"
          + this.connection.user + ":"
          + this.connection.password + "@"
          + this.connection.server + "/"
          + this.connection.database + "/"
          + pID;
  
      fetch(document)
          .then((response) =&gt; response.text())
          .then((responseText) =&gt; {
  
              result = responseText;
              Alert.alert('Fetch', result , [{text: 'ok'}])
  
          }).catch((error) =&gt; {
          console.warn(error);
      });
  
      Alert.alert('_getDocument', result , [{text: 'ok'}])
  
      return result;
  }
  </code></pre>
  
  <p>at the end of my function the variable result still has the value "getDocument failed" and not my json string.
  i already tried to store my response text somewhere else by calling another function but that didn't work as well.</p>