1

I cannot figure out how to parse a CSV file into an array which can be displayed in React JS.

I tried using PapaParse and react-papaparse, but neither allowed me to return the csv as an array.

This is essential in React JS because the way components are created is by returning them from a function.

In the examples for Papaparse and react-papaparse, they merely write the array to the console, but you cannot return the value of the array from the function because they use their complete keyword to read the array and call the handler function rather than simply allowing you to parse the CSV to an array which can be stored in a variable.

Please provide a working example of how I can parse a CSV file to an array which I can return from a function and thus add to my react virtual dom.

Jack N
  • 324
  • 2
  • 14
  • I don’t know how to help you with your specific problem, but ignoring PHP for a moment, do you have a working example of React consuming a (presumably) JSON array over (presumably) HTTP? From there, can you generate the JSON in PHP, still ignoring CSV? – Chris Haas Aug 25 '22 at 02:26

1 Answers1

0

For anyone wondering, the solution is to use the setState() react js function in order to update the property you would like to in the function that is specified in the papaparse complete section.

Jack N
  • 324
  • 2
  • 14