0

I want to display data from local csv with PapaParse. When I'm trying to do this code I only see array in console.log().

    renderRows = () => {
        const myData = require('./data.txt');
        papaparse.parse(myData, {
          download: true,
          delimiter: '\t',
          complete: function (results) {
            console.log(results);
            const rows = results.data.map((result, index) => (
              <tr key={index}>
                <td>{result}</td>
              </tr>))
            return (rows);
          }
        });
      }
      render() {
        return (
          <div>
            This is table
            <table>
                {this.renderRows()}
            </table>
          </div>
        ); }
}
EnzyWeiss
  • 198
  • 1
  • 2
  • 12

1 Answers1

0

So when you expect the var myData to be the content of the file required, you need to register a custom loader for the file type txt (or csv).

Read here: https://stackoverflow.com/a/12753026/2379376

After that everything should work.

Daniel
  • 1,933
  • 12
  • 17