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

Enhancement: Await `data` function in `CSVDownloader` #146

Closed JakeHaitsma closed 10 months ago

JakeHaitsma commented 1 year ago

I have a scenario where I want a download button (CSVDownloader) to trigger and await an asynchronous data fetch before downloading the CSV. Currently, I am rendering two components (one to kick off the data request and CSVDownloader to download once that data has been retrieved. It would be nice if CSVDownloader awaited data when it is provided as a function so the extra component was unnecessary.

<CSVDownloader
  filename={'filename'}
  data={async () => {
    // fetch some data, set loading state, etc
    await new Promise(resolve => setTimeout(resolve, 1000));

    return [
      {
        "Column 1": "1-1",
        "Column 2": "1-2",
        "Column 3": "1-3",
        "Column 4": "1-4",
      }
    ]}
  }
>
  Download
</CSVDownloader>
crice88 commented 1 year ago

Could really use this feature. Any ideas on a timeline?

danwdart commented 1 year ago

Is there a workaround?

jrecinos-applaudo commented 10 months ago

any news of this issue @Bunlong ?

Bunlong commented 10 months ago

The feature was added in latest version. Thanks!