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
363 stars 60 forks source link

setState from streaming worker thread? #145

Open evbo opened 1 year ago

evbo commented 1 year ago

Hi,

all of the examples discussed in this prior issue log the step results to the console, but how could you store the stream as state to a react component instead of just logging it?

Examples in prior issue about how to stream: https://github.com/Bunlong/react-papaparse/issues/59

Example in docs: https://github.com/Bunlong/react-papaparse/blob/d159bc5cfb6f40e63e4ddf5937ef7df5bdb93a8e/docs/src/components/screens/indexes/Worker.js

The reason I ask is because this is running in a separate thread, which requires window listeners to post results back to the main rendering thread doesn't it? Does this library (plan to) handle that?

For example, here's how it could be done: https://bokandp.medium.com/web-workers-with-react-ad495bd11e8b https://www.newline.co/fullstack-react/articles/introduction-to-web-workers-with-react/