@@ -13,13 +13,15 @@ Export data in React to CSV and other file formats
13
13
``` typescript
14
14
< FileDownloadLink
15
15
fileType = " CSV"
16
- columnNames = {[" Fruit" , " Price" ]}
17
16
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
+ }}
23
25
>
24
26
Download data
25
27
< / FileDownloadLink >
@@ -33,18 +35,22 @@ export type FileDownloadLinkProps = {
33
35
fileType: FileType ;
34
36
/** The text encoding of the data, utf-8 by default. */
35
37
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 ;
40
43
/** The filename for the exported file. */
41
44
filename? : string ;
42
45
/** A function to be called when the link is clicked before the data is downloaded.
43
46
* 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.
45
53
*/
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. */
48
54
setsDataAsyncInOnClick? : boolean ;
49
55
/** The content for rendering the link. */
50
56
children: React .ReactNode ;
0 commit comments