title: React setState with callback and pass props
body: <p>I have a file upload component (I'm working in React) that triggers a file upload with an on click handler. I want to display a loading icon whilst the upload is in progress. So I have a loading state that I set to true when the file handler function is called. However the state change is only sometimes rendered before the file upload begins, during which time the browser freezes. So I searched around and found that I can pass a callback to setState which will fire after the state changes and the component re-renders. However in my situation I need to pass the files collected from the event to this callback function... but this is not working. I have tried:</p>
  
  <pre><code>handleFile(files) {
  
      this.setState({ loading: true }, () =&gt; {
           console.log(files)
           // here is where I want to read the files
      })
  }
  </code></pre>
  
  <p>-- This logs: Filelist {length: 0}</p>
  
  <pre><code>handleFile(files) {
  
      this.setState({ loading: true }, (files) =&gt; {
           console.log(files)
           // here is where I want to read the files
      })
  }
  </code></pre>
  
  <p>-- This logs undefined.</p>
  
  <p>Any ideas where I am going wrong with this? BTW the event is handled in another function and the event target (the files) are being passed to the handleFiles function, the problem seems to be passing the files to the callback.</p>
  
  <p>Thanks</p>