react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString,
react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString,
react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
react-papaparse is available on npm. It can be installed with the following command:
npm install react-papaparse --savereact-papaparse is available on yarn as well. It can be installed with the following command:
yarn add react-papaparse --saveTo learn how to use react-papaparse:
…………Just pass in the js object with an optional configuration ( setting delimiter / separator ).
Note: If you want to open your CSV files in Excel, you might want to set bom={true} or bom, default is false. This option adds the so called BOM byte '\ufeff' to the beginning of your CSV files and tells Excel that the encoding is UTF8.
import React from 'react';
import { useCSVDownloader } from 'react-papaparse';
export default function CSVDownloader() {
const { CSVDownloader, Type } = useCSVDownloader();
return (
Download
);
}import React from 'react';
import { useCSVDownloader } from 'react-papaparse';
export default function CSVDownloader() {
const { CSVDownloader, Type } = useCSVDownloader();
return (
Download
);
}data={} can be a synchronous or asynchronous function that returns a data object.
import React from 'react';
import { useCSVDownloader } from 'react-papaparse';
export default function CSVDownloader() {
const { CSVDownloader } = useCSVDownloader();
return (
{
return [
{
"Column 1": "1-1",
"Column 2": "1-2",
"Column 3": "1-3",
"Column 4": "1-4",
}
]}
}
>
Download
);
}…import React from 'react';
import { usePapaParse } from 'react-papaparse';
export default function ReadRemoteFile() {
const { readRemoteFile } = usePapaParse();
const handleReadRemoteFile = () => {
readRemoteFile(url, {
complete: (results) => {
console.log('---------------------------');
console.log('Results:', results);
console.log('---------------------------');
},
});
};
return handleReadRemoteFile()}>readRemoteFile;
}…If you tell react-papaparse there is a header row, each row will be organized by field name instead of index.
import { usePapaParse } from 'react-papaparse';
const { readString } = usePapaParse();
readString(csvString, {
header: true,
worker: true,
complete: (results) => {
console.log('---------------------------');
console.log(results);
console.log('---------------------------');
},
});That's what streaming is for. Specify a step callback to receive the results row-by-row. This way, you won't load the whole file into memory and crash the browser.
import { usePapaParse } from 'react-papaparse';
const { readRemoteFile } = usePapaParse();
readRemoteFile(url, {
step: (row) => {
console.log('Row:', row.data);
},
complete: () => {
console.log('All done!');
}
});Latest version 4.4.0 (2023-10-14):
Version 4.3.0 (2023-10-10):
Version 4.2.2 (2023-10-09):
Version 4.2.0 (2023-10-07):
Version 4.1.0 (2022-08-07):
Version 4.0.4 (2022-08-06):
Version 4.0.2 (2022-01-26):
Version 4.0.1 (2022-01-21):
Version 4.0.0 (2022-01-18):
Details changes for each release are documented in the CHANGELOG.md.
If you think any of the react-papaparse can be improved, please do open a PR with any updates and submit any issues. Also, I will continue to improve this, so you might want to watch/star this repository to revisit.
We'd love to have your helping hand on contributions to react-papaparse by forking and sending a pull request!
Your contributions are heartily ♡ welcome, recognized and appreciated. (✿◠‿◠)
How to contribute:
Bunlong
Tim Tutt
Pieter Kuppens
Jack Zhao
Pablo Menichini
Mystical Tech
Bruno
Samuel Hulla
glinkot
Paul Leavitt
Gabriel
Izaak
Oliver
Ole Skaar
Des
Karl
Max
Kostas
Dalitzky
John Quinlivan
Gareth Jones
Chrys Exaucet
Stefee
Christopher Thomas
Venelin Banov
Joey Baker
Michiel De Mey
Mohammed Hussam
Xiaochao Liu
Jake HaitsmaYou maybe interested.
No open issues yet, or sync has not completed.