title: Why is not the state updated?
body: <p>I have a function that updates a state with a change and adds a value, but the state in the 'addResponse' function does not always change:</p>
  
  <pre><code>handleSelected (e, item) {
      this.setState({
          current_component_id: item.id,
      }, () =&gt; this.addResponse()
      );
  };
  </code></pre>
  
  <p>Call function above:</p>
  
  <pre><code>addResponse (e) {
      const { enrollment_id, evaluation_id, user_id, question_id, current_component_id, 
      responses, current_question, current_question_id 
      } = this.state;
      console.log(current_component_id)
  
      if (current_component_id != 0) {
  
          const newResponse = {
              enrollment_id: enrollment_id,
              evaluation_id: evaluation_id,
              user_id: user_id,
              question_id: current_question_id,
              answer_component: current_component_id,
          };
  
          function hasAnswer(res) {
              const list_question_id = res.map((item) =&gt; {
                  return item.question_id
              });
              if (list_question_id.includes(current_question_id)) {
                  return true
              } else {
                  return false
              }
          }
  
          if (responses === undefined) {
              this.setState({
                  responses: [newResponse]
              } 
              , () =&gt; console.log('---------&gt; primeiro', this.state.responses)
              )
          } else {
              const check = hasAnswer(responses);
              if (check) {
                  this.setState(prevState =&gt; {
                      prevState.responses.map((item, j) =&gt; {
                          if (item.question_id === current_question_id) {
                              return item.answer_component = current_component_id
                          }
                          return item ;
                      })
                  }
                  , () =&gt; { console.log('----&gt; questao alterada ', this.state.responses)}
                  )
  
              } else {
                  this.setState({
                      responses: [...this.state.responses, newResponse]
                      }
                      , () =&gt; console.log('------&gt; questao nova', this.state.responses)
                      );
              }
          }
      }
  
      // this.nextQuestion();
  };
  </code></pre>
  
  <p>the first console.log is always correct, but the others do not always change, I know that setState is asyn, but I thought that as I call the addResponse function it would be async</p>