Registry / data / react-csv

react-csv

JSON →
library2.2.2jsnpmunverified

react-csv is a React component library for generating Comma Separated Values (CSV) files directly from data within a React application. It supports various input data formats, including arrays of arrays, arrays of literal objects, and pre-formatted strings. The library provides two primary components: `CSVLink` for creating an HTML anchor element that triggers a CSV download, and `CSVDownload` for initiating an immediate download programmatically. The current stable version is 2.2.2, though development activity appears to have slowed, with the last publish being four years ago. It handles common scenarios like custom headers, nested data (via dot notation), and supports various browser environments with specific fixes for Safari and Chrome. It differentiates itself by offering straightforward components to directly output CSV from client-side React state or props, without requiring server-side processing for basic CSV generation.

npm install react-csv
INSTALL
IMPORT
SIG · REACT-CSV
R
react-csv
datajavascriptv2.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CSVLink
import { CSVLink } from 'react-csv';
import CSVLink from 'react-csv'; const CSVLink = require('react-csv').CSVLink;
CSVLink is a named export. It's the primary component for triggering downloads via a link element.
CSVDownload
import { CSVDownload } from 'react-csv';
import CSVDownload from 'react-csv'; const CSVDownload = require('react-csv').CSVDownload;
CSVDownload is a named export. Use it to trigger an immediate, programmatic download.
CommonJS (all exports)
const { CSVLink, CSVDownload } = require('react-csv');
const ReactCSV = require('react-csv'); const CSVLink = ReactCSV.CSVLink;
This pattern works for CommonJS environments, typically Node.js or older bundlers. ESM is preferred for modern React projects.
Types
import type { CSVLinkProps, CSVDownloadProps } from 'react-csv';
TypeScript definitions for react-csv are available via @types/react-csv.

This quickstart demonstrates how to use both `CSVLink` to create a downloadable link and how `CSVDownload` can trigger a direct download, providing basic CSV data from an array of arrays.

import React from 'react'; import { CSVLink, CSVDownload } from 'react-csv'; const csvData = [ ["firstname", "lastname", "email"], ["Ahmed", "Tomi", "ah@smthing.co.com"], ["Raed", "Labes", "rl@smthing.co.com"], ["Yezzi", "Min l3b", "ymin@cocococo.com"] ]; function CsvExportComponent() { return ( <div> <h2>Download CSV Examples</h2> <p>Click the link to download the CSV:</p> <CSVLink data={csvData} filename="my-data.csv">Download me as a link</CSVLink> <br /><br /> <p>Or trigger an immediate download (e.g., on page load, or a button click handler):</p> <button onClick={() => alert('CSV will download shortly (check browser downloads)')}> Initiate direct download (check console for real usage) </button> {/* This component will trigger a download immediately on render if not controlled */} {/* For a real use case, CSVDownload would be conditionally rendered or part of a click handler */} {/* <CSVDownload data={csvData} target="_blank" filename="my-direct-download.csv" /> */} </div> ); } export default CsvExportComponent;
Debug
Known issues
breakingThe `componentWillReceiveProps` lifecycle method, deprecated in React 16.3, was addressed in `react-csv` v2.0.1. Older versions of `react-csv` may cause warnings or issues with newer React versions.
fix
Upgrade to `react-csv` version 2.0.1 or higher to resolve `componentWillReceiveProps` warnings and improve compatibility with modern React versions.
affects: <2.0.1
gotchaVersion 2.0.1 migrated the build runtime environment from Node.js 6 to Node.js 13. While this primarily affects contributors, users building from source or with strict Node.js environment checks might encounter compatibility issues with older Node.js versions.
fix
Ensure your Node.js environment is Node.js 13 or newer if you are building `react-csv` from source or encountering build-time compatibility errors.
affects: >=2.0.1
gotchaOlder versions (prior to v1.1.2) had known issues with dot notation in headers for nested data and specific rendering problems in Internet Explorer 11. Safari downloads also had bugs in versions prior to v1.1.1 and v1.0.17.
fix
For improved browser compatibility and nested data handling, upgrade to `react-csv` version 1.1.2 or higher.
affects: <1.1.2
gotchaIn `react-csv` v1.0.14, the `buildURI` function was changed to use `URL.createObjectURL` to return a shorter URL for the CSV. This fixed a 'Chrome network error' but means the generated URI is no longer a long data URI.
fix
Be aware that generated CSV URIs are now short object URLs, which might affect how they are handled in certain contexts (e.g., logging, inspection) compared to the previous long data URIs.
affects: >=1.0.14
gotchaPrior to version 1.0.13, `null` values in data were downloaded as the string 'null' in the CSV output.
fix
Upgrade to `react-csv` version 1.0.13 or higher to correctly handle `null` values, which will typically be rendered as empty cells in the CSV.
affects: <1.0.13
Errors
Common errors & fixes
Warning: componentWillReceiveProps has been renamed, and is not recommended for use.
Using an older version of `react-csv` with a modern React version (16.3+).
fix
Update `react-csv` to version 2.0.1 or newer: `npm install react-csv@^2`.
CSV download not working or opening correctly in Safari.
Known browser compatibility bugs in older `react-csv` versions, specifically affecting Safari's download mechanism.
fix
Upgrade `react-csv` to version 1.1.1 or higher: `npm install react-csv@^1.1.1`.
CSV output contains 'null' strings instead of empty cells for null data.
Versions of `react-csv` prior to 1.0.13 would serialize `null` values as the string 'null'.
fix
Upgrade `react-csv` to version 1.0.13 or higher: `npm install react-csv@^1.0.13`.
Getting 'Network Error' in Chrome or 'URI too long' errors for large CSVs.
Older `react-csv` versions generated very long data URIs for CSVs, which could exceed browser limits.
fix
Upgrade `react-csv` to version 1.0.14 or higher, which utilizes `URL.createObjectURL` to generate shorter, more robust URLs for downloads. `npm install react-csv@^1.0.14`.
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies
reactrequiredPeer dependency for any React component library. Required for rendering the components.
react-domrequiredPeer dependency for any React component library. Required for rendering the components.
Agent activity
2 hits · last 30 days
node
2
Resources
react-csv — npm install react-csv · libregistry