
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
react-csv-downloader
Advanced tools
A simple react component to allow download CSV file from js object
npm install --save react-csv-downloader
Use with children component
import CsvDownloader from 'react-csv-downloader';
<CsvDownloader>
<button>Download</button>
</CsvDownloader>
Use without children component
<CsvDownloader text="Download"/>
pass the downloaded datas as a component prop
const datas = [{
cell1: 'row 1 - cell 1',
cell2: 'row 1 - cell 2'
}, {
cell1: 'row 2 - cell 1',
cell2: 'row 2 - cell 2'
}];
<CsvDownloader datas={datas}/>
pass the columns definition as a component prop to change the cell display name. If column isn't passed the cell display name is automatically defined with datas keys
const columns = [{
id: 'cell1',
displayName: 'Cell 1'
}, {
id: 'cell2',
displayName: 'Cell 2'
}];
<CsvDownloader columns={columns}/>
You can also use the columns definition to set the columns display order
Name | Type | Default | Required | Description |
---|---|---|---|---|
columns | array of object | null | false | Columns definition |
datas | array of object | null | true | Downloaded datas |
filename | string | null | true | You can pass the filename without extension. The extension is automatically added |
separator | string | ',' | false | Columns separator |
noHeader | boolean | false | false | If true the header isn't added to the csv file |
prefix | string or boolean | false | false | Filename prefix. If true prefix becomes a timestamp |
suffix | string or boolean | false | false | Filename suffix/postfix. If true suffix becomes a timestamp |
text | string | null | false | Download button text. Used if no children component. |
wrapColumnChar | string | '' | false | Character to wrap every data and header value with. |
bom | boolean | true | false | Activate or deactivate bom mode |
newLineAtEnd | boolean | false | false | Insert new line at end of file. |
All other props are passed to button or wrapping component.
pass the downloaded datas as a component prop
render() {
const columns = [{
id: 'first',
displayName: 'First column'
}, {
id: 'second',
displayName: 'Second column'
}];
const datas = [{
first: 'foo',
second: 'bar'
}, {
first: 'foobar',
second: 'foobar'
}];
return (
<div>
<CsvDownloader
filename="myfile"
separator=";"
wrapColumnChar="'"
columns={columns}
datas={datas}
text="DOWNLOAD" />
</div>
);
}
// content of myfile.csv
// 'First column';'Second column'
// 'foo';'bar'
// 'foobar';'foobar'
If you just need to get CSV contents, import react-csv-downloader/dist/lib/csv
function and use it directly.
FAQs
React csv downloader
The npm package react-csv-downloader receives a total of 17,459 weekly downloads. As such, react-csv-downloader popularity was classified as popular.
We found that react-csv-downloader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.