title: Function not loading inside componentDidMount ()
body: <p>I have the following code: </p>
  
  <pre><code>componentDidMount () {
      fetch('/data')
          .then(res =&gt; res.json())
          .then(data =&gt; this.setState({data}));
  
      this.countVar();
  }
  
  countVar () {
      //iterate through this.state.data and filter out certain values
  }
  </code></pre>
  
  <p>The <code>countVar()</code> function isn't loading inside <code>componentDidMount()</code>. When I did <code>console.log(this.state.data)</code> right after the <code>componentDidMount()</code>-function, it returned an empty array, so I guess that's the reason.
  I tried to use <code>componentDidUpdate()</code> instead if <code>countVar()</code>, but I didn't consider that that would create an infinite loop. I don't quite know how to handle this.</p>
  
  <p>The data that I'm fetching consists of several object arrays. in <code>countVar()</code> I'm filtering out a certain object array, hence the structure of my functions.</p>
  
  <p>Does anyone know how I could solve this problem?</p>