Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
364 stars 61 forks source link

onFileLoad receives an array of Papaparse results #105

Open kenlim opened 2 years ago

kenlim commented 2 years ago

Hello,

When parsing a simple file with the header option set to true, the onFileLoad callback receives a result that looks like an array of Papaparse result objects:

[ 
{ data : {header: "val", header2: "val2"}, 
  errors :[], 
  meta : { ...data}
}, 
{ data : {header: "val3", header2: "val4"}, 
  errors :[], 
  meta : { ...data}
}, 
{ data : {header: "val5", header2: "val6"}, 
  errors :[], 
  meta : { ...data}
}, 
]

When the same string is called with Papaparse directly (in a unittest), it comes back as a Result object with an array of rows in the Data field:

{
data: [ 
  {header: "val", header2: "val2"}, 
  {header: "val3", header2: "val4"},
  {header: "val5", header2: "val6"}
],
errors: [],
meta: { ...data}
}

Is this intended behaviour? Or am I missing something?

I have an example of the problem here: https://codesandbox.io/s/peaceful-forest-tj6br?file=/src/CsvReader.js

Bunlong commented 2 years ago

@kenlim

Yes, this is intended behaviour and I consider to follow the original one in version react-papaparse 4.0. Thanks!