react-papaparse - npm explorer

)}

);
}
`

$3

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.

#### Button

`javascript
import React from 'react';

import { useCSVDownloader } from 'react-papaparse';

export default function CSVDownloader() {
const { CSVDownloader, Type } = useCSVDownloader();

return (
type={Type.Button}
filename={'filename'}
bom={true}
config={{
delimiter: ';',
}}
data={[
{
'Column 1': '1-1',
'Column 2': '1-2',
'Column 3': '1-3',
'Column 4': '1-4',
},
{
'Column 1': '2-1',
'Column 2': '2-2',
'Column 3': '2-3',
'Column 4': '2-4',
},
{
'Column 1': '3-1',
'Column 2': '3-2',
'Column 3': '3-3',
'Column 4': '3-4',
},
{
'Column 1': 4,
'Column 2': 5,
'Column 3': 6,
'Column 4': 7,
},
]}
>
Download

);
}
`

#### Link

`javascript
import React from 'react';

import { useCSVDownloader } from 'react-papaparse';

export default function CSVDownloader() {
const { CSVDownloader, Type } = useCSVDownloader();

return (
type={Type.Link}
filename={'filename'}
bom={true}
data={
Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
#2-1,เคฎเฅเค•เฅ‡เคถ,แžแŸ’แž‰แžปแŸ†,2-4
3-1,3-2,แžขแŸ’แž“แž€,3-4
4,5,6,7}
>
Download

);
}
`

#### Data as a Function/Callback

data={} can be a synchronous or asynchronous function that returns a data object.

`javascript
import React from 'react';

import { useCSVDownloader } from 'react-papaparse';

export default function CSVDownloader() {
const { CSVDownloader } = useCSVDownloader();

return (
filename={'filename'}
data={() => {
return [
{
"Column 1": "1-1",
"Column 2": "1-2",
"Column 3": "1-3",
"Column 4": "1-4",
}
]}
}
>
Download

);
}
`

$3

`javascript
import React from 'react';

import { usePapaParse } from 'react-papaparse';

export default function ReadString() {
const { readString } = usePapaParse();

const handleReadString = () => {
const csvString =
Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
2-1,2-2,2-3,2-4
3-1,3-2,3-3,3-4
4,5,6,7;

readString(csvString, {
worker: true,
complete: (results) => {
console.log('---------------------------');
console.log(results);
console.log('---------------------------');
},
});
};

return ;
}
`

$3

`javascript
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 ;
}
`

$3

`javascript
import React from 'react';

import { usePapaParse } from 'react-papaparse';

export default function JsonToCSV() {
const { jsonToCSV } = usePapaParse();

const handleJsonToCSV = () => {
const jsonData = [
{
"Column 1": "1-1",
"Column 2": "1-2",
"Column 3": "1-3",
"Column 4": "1-4"
},
{
"Column 1": "2-1",
"Column 2": "2-2",
"Column 3": "2-3",
"Column 4": "2-4"
},
{
"Column 1": "3-1",
"Column 2": "3-2",
"Column 3": "3-3",
"Column 4": "3-4"
},
{
"Column 1": 4,
"Column 2": 5,
"Column 3": 6,
"Column 4": 7
}
];
const results = jsonToCSV(jsonData);
console.log('---------------------------');
console.log('Results:', results);
console.log('---------------------------');
};

return ;
}
`

#### Header Row Support

If you tell react-papaparse there is a header row, each row will be organized by field name instead of index.

`javascript
import { usePapaParse } from 'react-papaparse';

const { readString } = usePapaParse();

readString(csvString, {
header: true,
worker: true,
complete: (results) => {
console.log('---------------------------');
console.log(results);
console.log('---------------------------');
},
});
`

#### Stream

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.

`javascript
import { usePapaParse } from 'react-papaparse';

const { readRemoteFile } = usePapaParse();

readRemoteFile(url, {
step: (row) => {
console.log('Row:', row.data);
},
complete: () => {
console.log('All done!');
}
});
`

๐Ÿ“œ Changelog

Latest version 4.4.0 (2023-10-14):

* Handle parsing utf-8 bom encoded files
* Rename duplicate headers
* Improve iso-date regex

Version 4.3.0 (2023-10-10):

* Enable async callback function for CSVDownloader

Version 4.2.2 (2023-10-09):

* Fix type

Version 4.2.0 (2023-10-07):

* Upgrade dependencies

Version 4.1.0 (2022-08-07):

* Import readString, readRemoteFile and jsonToCSV as pure function

Version 4.0.4 (2022-08-06):

* Add optional required prop for input file

Version 4.0.2 (2022-01-26):

* Fix onUploadAccepted signature when a preview is set

Version 4.0.1 (2022-01-21):

* Fix config props does not work in CSVReader

Version 4.0.0 (2022-01-18):

* Improve code performance
* Rewrite any existing based components to hooks

Details changes for each release are documented in the CHANGELOG.md.

๐Ÿ›ฃ๏ธ Roadmap

$3

* CSVReader multiple files drag and drop

โ— Issues

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.

๐Ÿ’ช Contribution

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:

- Open pull request with improvements
- Discuss ideas in issues
- Spread the word
- Reach out with any feedback

๐Ÿ† Contributors












































Bunlong



Bunlong




Tim Tutt



Tim Tutt




Pieter Kuppens



Pieter Kuppens




Jack Zhao



Jack Zhao




Pablo Menichini



Pablo Menichini




Mystical Tech



Mystical Tech




Bruno



Bruno




Samuel Hulla



Samuel Hulla




glinkot



glinkot




Paul Leavitt



Paul Leavitt




Gabriel



Gabriel




Izaak



Izaak




Oliver



Oliver




Ole Skaar



Ole Skaar




Des



Des




Karl



Karl




Max



Max




Kostas



Kostas




Dalitzky



Dalitzky




John Quinlivan



John Quinlivan




Gareth Jones



Gareth Jones




Chrys Exaucet



Chrys Exaucet




Stefee



Stefee




Christopher Thomas



Christopher Thomas




Venelin Banov



Venelin Banov




Joey Baker



Joey Baker




Michiel De Mey



Michiel De Mey




Mohammed Hussam



Mohammed Hussam




Xiaochao Liu



Xiaochao Liu




Jake Haitsma



Jake Haitsma


๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Advertisement

You maybe interested.

* React Patterns โ€“ React patterns & techniques to use in development for React Developer.
* Next Share โ€“ Social media share buttons for your next React apps.
* Next QRCode โ€“ React hooks for generating QR code for your next React apps.
* Next Time Ago โ€“ A lightweight tiny time-ago component for your next React apps.

โš–๏ธ License

The MIT License ![License: MIT](https://opensource.org/licenses/MIT)