title: How to read and parse CSV with react and Papaparse
body: <p>I've been trying to read and parse a CSV file through React and its near impossible for me to find a way it would work.</p>
  
  <p>I would really appreciate the help.</p>
  
  <p>P.S: Thank you in advance for your help.</p>
  
  <p>I'm trying to read a CSV file and then format it with PapaParse. The problem I'm encountering is the actual way I'm trying to achieve this is by the following one</p>
  
  <p><code>FetchCSV.js</code> looks like this:</p>
  
  <pre><code>import React from 'react';
  import Papa from 'papaparse';
  import {withRouter} from 'react-router-dom';
  
  class DataController extends React.Component {
  
      constructor(props) {
          super(props);
  
          this.state = {
              data: []
          };
  
          this.getData = this.getData.bind(this);
      }
  
      componentWillMount() {
          this.getCsvData();
      }
  
      fetchCsv() {
          return fetch('/data/data.csv').then(function (response) {
              let reader = response.body.getReader();
              let decoder = new TextDecoder('utf-8');
  
              return reader.read().then(function (result) {
                  return decoder.decode(result.value);
              });
          });
      }
  
      getData(result) {
          this.setState({data: result.data});
      }
  
      async getCsvData() {
          let csvData = await this.fetchCsv();
  
          Papa.parse(csvData, {
              complete: this.getData
          });
      }
  
      render() {
          return (
              &lt;section className="data-controller"&gt;
                  ...
              &lt;/section&gt;
          );
      }
  }
  
  export default FetchCSV;
  </code></pre>
  
  <p>I'm getting a problem like this: <code>no-undef</code>with <code>FetchCSV</code>, I also want to try to get the result on my console but I can't find where to put the <code>console.log(result);</code> (which is making things really hard for me). It's also important to mention that I placed this in the <code>App.js</code>: <code>import FetchCSV from "./FetchCSV"</code> (which I believe is the way it needs to be added).</p>