title: Pull to Refresh and setState not working - React Native
body: <p>React Native App <br/>
  I am implementing Pull to refresh in my Flatlist prop "onRefresh" <br/>
  onRefresh called the function "refreshcontrol()" see code below. <br/>
  I need to change my state "refreshing" to true before I fetch from my API. But it throws the maximum update error.</p>
  
  <pre><code>export default class NotificationScreen extends Component {
  
  
    constructor(props) {
     super(props)
     this.state = {
        refreshing: false 
      }
    }
  .
  .
  .
  .
  .
    refreshControl() {
      const { refreshing } = this.state;
      this.setState({ refreshing : true )}.    // throws maximum update error
  
      return (
        &lt;RefreshControl
          refreshing={refreshing}
          onRefresh={fetchNotifications.bind(this)}      //fetch from API only when refreshing is true
          colors={['#2B70AD']}
        /&gt;
      );
    };
  
  
  }
  </code></pre>
  
  <p>How else can I set my state to "refreshing :  true" ??? Help please!!!!</p>
  
  <p>This is how it was fixed. Solution:</p>
  
  <pre><code>refresh = async() =&gt; {
      this.setState({refreshing : true})
      try {
        const notifications = await fetchNotifications();
        this.setState({
          notifications,
          error: null,
          refreshing: false
        });
      } catch (error) {
        this.setState({
          notifications: [],
          error,
          refreshing: false
        });
      }
    }
  
    refreshControl() {
      const { refreshing } = this.state;
  
      return (
        &lt;RefreshControl
          refreshing={refreshing}
          onRefresh={this.refresh}
          colors={['#2B70AD']}
        /&gt;
      );
    };
  
  </code></pre>