title: Rejection (TypeError): Cannot read property 'setState' of undefined, Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
body: <p>I have a simple code, but I receiving (sometimes) wrong results, it's because of NodeJS async, I know. Finally I need do update "this.setState({active: options})". So to solve the issue of async of NodeJS I used the require("async") library. But now my simple code got quite complex, and the result is also not 100% good. </p>
  
  <p>And also at the on "function road" when i use the "this.setState({actove: options})", or "this.setState({actove: results.optionsFill})", I receive errors: "Unhandled Rejection (TypeError): Cannot read property 'setState' of undefined" and "Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined".</p>
  
  <p>Please see the simple start code (the code calculates the legend input to a map, the arr for number periods):</p>
  
  <pre><code>    setLegend(data){
  
          function roundingSize(number){
          }
  
          function rounding(number){
          }
  
          function stopsArrFill(jumpLegendValue, highestNumber){
          }
  
          // Searching for the highestNumber POPULATION
          var highestNumber = 0
  
          data.features.forEach(element =&gt; {
               var value = element.properties["POPULATION"]           
               if(highestNumber&lt;value) highestNumber = value
          })
  
          // Need to round the number, so it will look nice on the legend
          highestNumber = roundingSize(highestNumber)
  
          // Searching for the LowestNumber POPULATION
          var LowestNumber = highestNumber
  
          data.features.forEach(element =&gt; {
              var value = element.properties["POPULATION"]
              if(LowestNumber&gt;value) LowestNumber = value
          })
  
          // Need to round the number, so it will look nice on the legend
          LowestNumber = roundingSize(LowestNumber)
  
          // 7 because 1 element is 0 and the last is the highestNumber, so it gives 7 empty elements to fill
          var jumpLegendValue = Math.round(rounding((highestNumber - LowestNumber)/7))
  
          var tmpStops  = stopsArrFill(jumpLegendValue, highestNumber)
  
          const options = {
              name: 'Legenda',
              description: 'Liczba wystąpień',
              property: 'POPULATION',
              stops: tmpStops
          }
  
          this.setState({active: options})
  </code></pre>
  
  <p>Now the complex code with async.auto:</p>
  
  <pre><code>    setLegend(data){
  
          function roundingSize(number){
          }
  
          function rounding(number){
          }
  
          function stopsArrFill(jumpLegendValue, highestNumber){
          }
  
          async.auto({
  
              highestNumber: function(callback){
  
                  // Searching for the highestNumber POPULATION
                  var highestNumber = 0
  
                  data.features.forEach(element =&gt; {
                      var value = element.properties["POPULATION"]           
                      if(highestNumber&lt;value) highestNumber = value
                  })
  
                  // Need to round the number, so it will look nice on the legend
                  highestNumber = roundingSize(highestNumber)
  
                  callback(null, highestNumber)
              },
              lowestNumber: ['highestNumber', function(results, callback){
  
                  // Searching for the LowestNumber POPULATION
                  var lowestNumber = results.highestNumber
  
                  data.features.forEach(element =&gt; {
                      var value = element.properties["POPULATION"]
                      if(lowestNumber&gt;value) lowestNumber = value
                  })
  
                  // Need to round the number, so it will look nice on the legend
                  lowestNumber = roundingSize(lowestNumber)
  
                  callback(null, lowestNumber)
              }],
              jumpLegendValue: ['highestNumber', 'lowestNumber', function(results, callback){
  
                  // 7 because 1 element is 0 and the last is the highestNumber, so it gives 7 empty elements to fill
                  var jumpLegendValue = Math.round(rounding((results.highestNumber - results.lowestNumber)/7))
  
                  callback(null, jumpLegendValue)
              }],
              stopsArrFill:['highestNumber','jumpLegendValue', function(results, callback){
  
                  // Filling the stops with jumpLegendValues
                  var tmpStops  = stopsArrFill(results.jumpLegendValue, results.highestNumber)
  
                  callback(null, tmpStops)
              }],
              optionsFill:['stopsArrFill', function(results, callback){
  
                  const options = {
                      name: 'Legenda',
                      description: 'Liczba wystąpień',
                      property: 'POPULATION',
                      stops: results.stopsArrFill
                  }      
  
                  callback(null, options)
              }],
              function (err, results)
              {
                  this.setState({active:results.optionsFill})
                  console.log('error: ', err)
              }
          })
  </code></pre>
  
  <p>I am now playing around with this for 2 days, do you  have any ideas / suggestions? I couldn't find any similar usage for setState with async.auto. </p>