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

CSVDownloader data should accept callback to reduce computation #92

Closed BirdTho closed 3 years ago

BirdTho commented 3 years ago

I have a scenario where I want to make a list of results downloadable based on test output. During output though, there's no marker for the 'end' of the test, it could be saved at any point. In that, I have something like this:

const eventList = useRecoilValue(eventListAtom);
  const resolution = useRecoilValue(resolutionAtom);
  const vastUrl = useRecoilValue(urlAtom);
  const isVPAID = useRecoilValue(isVPAIDAtom);

  return (
    <CSVDownloader
      data={jsonToCSV({
        eventList,
        resolution,
        vastUrl,
        isVPAID,
      })}
      type="button"
      filename={[isVPAID ? 'VPAID' : resolution, vastUrl ? (new URL(vastUrl)).hostname : 'null', eventList.length.toString(10)].join('_')}
      bom={true}
    >
      Download
    </CSVDownloader>
  );

data={} doesn't accept a function or callback. Because I'd only like to calculate this data on click.

Buvaneshkumar7 commented 2 years ago

@Bunlong can we have it as an Async Function