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-csvVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to `react-csv` version 2.0.1 or higher to resolve `componentWillReceiveProps` warnings and improve compatibility with modern React versions.
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.
For improved browser compatibility and nested data handling, upgrade to `react-csv` version 1.1.2 or higher.
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.
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.
Update `react-csv` to version 2.0.1 or newer: `npm install react-csv@^2`.
Upgrade `react-csv` to version 1.1.1 or higher: `npm install react-csv@^1.1.1`.
Upgrade `react-csv` to version 1.0.13 or higher: `npm install react-csv@^1.0.13`.
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`.