title: Data not available when File loading with PapaParse and React (on first pass only)
body: <p>Trying to load a local file using PapaParse. The code snippets below only seems to work after selecting a file 2nd time round(and thereafter). Have tried useEffect but still hit the same issue. Tried setting a 5sec delay too. Any help much appreciated.</p>
  <pre><code>const UploadMORFile = (props) =&gt; {
      const { openModal } = props; /* a simple carbon component for confirmation */
      const [parsedCsvData, setParsedCsvData] = useState([]);
  
      const onSelectFile = (event) =&gt; {
          if (!(event.target &amp;&amp; event.target.files &amp;&amp; event.target.files[0])) {
              return;
          }
  
      let filename = event.target.files[0].name;
  
      const config = {
          dynamicTyping: true,
          header: true,
          encoding: &quot;UTF8&quot;,
          skipEmptyLines: true,
          complete: (results) =&gt; {setParsedCsvData(JSON.stringify(results.data));
  /* console.log(`parsed data1: ${parsedCsvData}`) shows there is data in parsedCsvData */
        },
      };
  
      Papa.parse(event.target.files[0], config);
  
      if (parsedCsvData) {
          openModal({type: &quot;confirm&quot;,
          heading: `You have selected to upload MOR data from ${filename}. Do you wish to continue?`,
          callback: () =&gt; fileUpload(parsedCsvData),
          });
      }
    };
  /* console.log(`parsed data2: ${parsedCsvData}`) shows there is data in parsedCsvData */
  
  Problem is that the call to fileUpload function does not contain data on first execution. I suspect it's an asynchronous issue?[enter image description here][1]
  </code></pre>