title: React Native: Fetch data every 10 clicks on a button
body: <p>I've just started working with React Native a few days ago and I find myself a bit stuck. I want to display the values one by one from an api with the click of a button. However, how can I do this without fetching the data every single time, but rather every 10 clicks or so? The code I have right now doesn't work the way I want it to and I do understand why - the countData() function is always called anew, therefore the variable i is always stuck at zero and never advances forward. Ideally, I'd like to loop through the first set of values, display them one by one as the button is clicked and then fetch new data (from the same api) after it runs out of values.</p>
  
  <pre><code>export default class ComponentOne extends Component {
  
   constructor(props) {
   super(props);
   this.state = {
     questions: '',
     questions2: '',
   }
  }
  
  
  fetchData() {
    if (this.state.questions == '') {
     fetch('my url')
      .then((response) =&gt; response.json())
      .then((responseData) =&gt; {
          this.setState({
              questions: responseData,
          });
      this.countData();
     })
      .done();
    }
    else this.countData();
   }
  
  countData() {
    for (let i=0; i &lt; this.state.questions.length; i++) {
     this.setState({
      questions2: this.state.questions[i],
    });
   }
  }
  
  render() {
   return (
    &lt;View style={styles.container}&gt;
  
       &lt;View style={styles.textStyle}&gt;
  
       &lt;Text style={styles.instructions}&gt;
         Welcome! Click the button to generate a question.
       &lt;/Text&gt;
  
       &lt;TouchableHighlight
       onPress={() =&gt; this.fetchData()}
       style={styles.bigButton}
       underlayColor="lightskyblue"&gt;
  
         &lt;Text style={styles.bigButtonText}&gt;Hit me&lt;/Text&gt;
  
       &lt;/TouchableHighlight&gt;
  
       &lt;Text style={styles.question}&gt;{this.state.questions2}&lt;/Text&gt;
       &lt;/View&gt;
    &lt;/View&gt;
    );
   }
  }
  </code></pre>
  
  <p>I hope the problem is clear, thanks in advance!</p>