title: Call this.setState() in React Native from Inside Callback Function
body: <p>I am new to React Native and am trying to parse XML into a FlatList and then save it to the State object. In order to parse the XML, I am using react-native-xml2js and the simple function, parseString. The parseString has a callback function and I am trying to use the setState function within that callback function. However, "this" is undefined in the callback and, when I try to pass "this" as a different variable (in this case, "self"), it's still undefined. What am I doing wrong here?</p>
  
  <pre><code>export default class PostList extends Component&lt;{}&gt; 
  {
  
     constructor(props) {
        super(props);
        this._executeQuery('https://website.com/xml-feed/');
        this.state = {
          resultsLoaded: false,
          results: false,
        };
      };
  
    _keyExtractor = (item, index) =&gt; index;
    _renderItem = ({item, index}) =&gt; (
        &lt;ListItem
          item={item}
          index={index}
          onPressItem={this._onPressItem}
        /&gt;
      );
      _renderList = (response) =&gt; {
          return &lt;FlatList
          data={response.rss.channel[0].item}
          keyExtractor={this._keyExtractor}
          renderItem={this._renderItem}
        /&gt;;
      };
      _handleResponse = (response) =&gt; {
          var parseString = require('react-native-xml2js').parseString;
          var self = this;
          this.setState({ resultsLoaded: true });
          parseString(response, function (err, result, self) {
              console.log(self);
              self.setState({ resultsLoaded: true, results: self._renderList(result) });
          });
      };
      _executeQuery = (query) =&gt; {
        fetch(query)
            .then(response =&gt; response.text())
            .then(str =&gt; this._handleResponse(str))
            .catch(error =&gt;
               console.log('ERROR: '+error)
           );
      };
  
    render() {
      const results = this.state.resultsLoaded ?
          this.state.results : null;
      const loading = !this.state.resultsLoaded ?
              (&lt;View&gt;&lt;Text style={styles.description}&gt;
            Loading Blog Posts
          &lt;/Text&gt;
          &lt;ActivityIndicator size='large'/&gt;&lt;/View&gt;) : null;
              console.log(this.state.resultsLoaded);
      return (
        &lt;View style={styles.container}&gt;
          {loading}
          {results}
        &lt;/View&gt;
      );
    };
  
  }
  </code></pre>