Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-csv

Package Overview
Dependencies
Maintainers
3
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-csv

Build CSV files on the fly basing on Array/literal object of data

  • 2.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
395K
decreased by-16.72%
Maintainers
3
Weekly downloads
 
Created

What is react-csv?

The react-csv package is a simple and powerful library for handling CSV (Comma-Separated Values) files in React applications. It allows you to easily generate and download CSV files directly from your React components.

What are react-csv's main functionalities?

Download CSV

This feature allows you to create a link that, when clicked, will generate and download a CSV file with the provided data. The CSVLink component takes in the data and filename as props.

import { CSVLink } from 'react-csv';

const data = [
  { firstname: 'John', lastname: 'Doe', email: 'john.doe@example.com' },
  { firstname: 'Jane', lastname: 'Doe', email: 'jane.doe@example.com' }
];

const DownloadCSV = () => (
  <CSVLink data={data} filename={"my-file.csv"}>
    Download me
  </CSVLink>
);

Export CSV

This feature allows you to programmatically trigger a CSV file download. The CSVDownload component can be used to immediately start the download when the component is rendered.

import { CSVDownload } from 'react-csv';

const data = [
  { firstname: 'John', lastname: 'Doe', email: 'john.doe@example.com' },
  { firstname: 'Jane', lastname: 'Doe', email: 'jane.doe@example.com' }
];

const ExportCSV = () => (
  <CSVDownload data={data} target="_blank" />
);

Custom Headers

This feature allows you to define custom headers for your CSV file. The headers prop takes an array of objects, each containing a label and a key, which maps to the data fields.

import { CSVLink } from 'react-csv';

const headers = [
  { label: 'First Name', key: 'firstname' },
  { label: 'Last Name', key: 'lastname' },
  { label: 'Email', key: 'email' }
];

const data = [
  { firstname: 'John', lastname: 'Doe', email: 'john.doe@example.com' },
  { firstname: 'Jane', lastname: 'Doe', email: 'jane.doe@example.com' }
];

const CustomHeadersCSV = () => (
  <CSVLink data={data} headers={headers} filename={"custom-headers.csv"}>
    Download with Custom Headers
  </CSVLink>
);

Other packages similar to react-csv

Keywords

FAQs

Package last updated on 18 Jan 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc