Skip to content

Commit 1035478

Browse files
author
erik_ritter
committed
Iterate more on async case
1 parent d44393b commit 1035478

File tree

5 files changed

+539
-56
lines changed

5 files changed

+539
-56
lines changed

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ Export data in React to CSV and other file formats
1313
```typescript
1414
<FileDownloadLink
1515
fileType="CSV"
16-
columnNames={["Fruit", "Price"]}
1716
filename="fruits"
18-
rows={[
19-
["Apple", 1],
20-
["Watermelon", 5],
21-
["Durian", 10],
22-
]}
17+
data={{
18+
columnNames: ["Fruit", "Price"],
19+
rows: [
20+
["Apple", 1],
21+
["Watermelon", 5],
22+
["Durian", 10],
23+
],
24+
}}
2325
>
2426
Download data
2527
</FileDownloadLink>
@@ -33,18 +35,22 @@ export type FileDownloadLinkProps = {
3335
fileType: FileType;
3436
/** The text encoding of the data, utf-8 by default. */
3537
encoding?: string;
36-
/** The column names of the data. */
37-
columnNames: (string | number)[];
38-
/** The rows of the data. */
39-
rows: (string | number)[][];
38+
/** The data to download. Can be null if the data is set in onClick. */
39+
data: {
40+
columnNames: (string | number)[];
41+
rows: (string | number)[][];
42+
} | null;
4043
/** The filename for the exported file. */
4144
filename?: string;
4245
/** A function to be called when the link is clicked before the data is downloaded.
4346
* If this function modifies the data to be downloaded, then you must set
44-
* setsDataAsyncInOnClick to true and call the `download` function when complete.
47+
* setsDataAsyncInOnClick to true.
48+
*/
49+
onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;
50+
/** If the data is set asynchronously in onClick, then this must be set to true.
51+
* Setting this to true will result in an automatic download of data at the next time
52+
* the data changes.
4553
*/
46-
onClick?: (e: React.MouseEvent<HTMLAnchorElement>, download: () => void) => void;
47-
/** If the data is set asynchronously in onClick, then this must be set to true. */
4854
setsDataAsyncInOnClick?: boolean;
4955
/** The content for rendering the link. */
5056
children: React.ReactNode;

0 commit comments

Comments
 (0)