title: React - Uncaught TypeError: Cannot read properties of undefined (reading 'setState')
body: <p>I'm not able to <code>setState</code> inside my callback function to be able to get the progress percentage of my S3 upload.</p>
  <p><strong>What I'm trying to do is to choose a file from pc, upload it to S3 and render it in my dom with a progress bar.</strong></p>
  <pre><code>class Dashboard extends React.Component {
      constructor(props) {
          super(props);
          this.state = { uri: &quot;&quot;, uploadProgress : 0 };
      }
  
      async onChange(e) {
          const file = e.target.files[0];
  
          //upload to S3, works great
          try {
              await Storage.put(file.name, file, {
                  progressCallback(progress) {
                      const prog = parseInt(progress.loaded/progress.total*100)
                      console.log(prog+&quot;%&quot;);
                      //undefined
                      this.setState({uploadProgress: prog})
                  },
                  contentType: file.type, // contentType is optional
              });
          } catch (error) {
              console.log(&quot;Error uploading file: &quot;, error);
          }
  
          //get from S3, works but not the setState
          try {
              const amen = await Storage.get(file.name, { expires: 60 });
  
              this.setState({
                  uri: amen
              })
  
          } catch (error) {
              console.log(&quot;Error file: &quot;, error);
          }
  
      }
  
      render() {
          return (
              &lt;div&gt;
                  &lt;input type= &quot;file&quot; onChange = { this.onChange } /&gt;
                  &lt;img src={this.state.uri}/&gt;
                  {this.state.uploadProgress &amp;&amp; &lt;ProgressBar now={this.state.uploadProgress} label={this.state.uploadProgress + &quot;%&quot;} /&gt;}
              &lt;/div&gt;
          )
      }
  }
  </code></pre>
  <p><strong>Everything works except this:</strong></p>
  <pre><code>this.setState({uploadProgress: prog})
  </code></pre>
  <p>I don't understand why I'm unable to call my state progress, what's wrong?</p>