title: Accessing state in react
body: <p>I have a function:</p>
  
  <pre><code>    getCommits: function() {
      fetch('/commits').then((response) =&gt; {
          if (response.status &gt;= 400) {
              throw new Error("Bad response from server");
          }
          return response.json();
       })
       .then((commits) =&gt; {
         this.setState({commits: commits});
       });
    },
  </code></pre>
  
  <p>I set the state in this function and now I want other functions to access this state. How can I do this?</p>
  
  <p><code>this.state.commits</code> was one idea I had.</p>
  
  <pre><code>     getTodaysCommits: function(){
       fetch('/commits').then((response) =&gt; {
          if (response.status &gt;= 400) {
              throw new Error("Bad response from server");
          }
          return response.json();
       })
       .then((commits) =&gt; {
         var todaysCommits = [];
         for (var i = 0; i &lt; commits.length; i++) {
           var today = new Date().toDateString();
           var stringToDate = new Date(commits[i].commit.author.date).toDateString();
           if (today == stringToDate){
             todaysCommits.push(commits[i])
           }
         }
         return todaysCommits;
       })
       .then((todaysCommits) =&gt; {
         this.setState({commits: todaysCommits});
       })
    },
  </code></pre>
  
  <p>In this function how can I use commits without having to fetch it from api and just use the state set in the previous function?</p>
  
  <pre><code>componentDidMount: function() {
      this.getCommits();}
  </code></pre>
  
  <p>I have my function that gets set on <code>componentDidMount</code></p>