React component that handles csv file input.
npm install react-csv-reader

!Node.js CI
!a11y axe
!TypeScript Support
React component that handles csv file input.
It handles file input and returns its content as a matrix.
Docs: nzambello.github.io/react-csv-reader
You can try it out in the playground in the docs or in the demo on Codesandbox.
Install the package with either yarn or npm.
With yarn:
``sh`
yarn add react-csv-reader
With npm:
`sh`
npm install --save react-csv-reader
Basic usage:
`javascript
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import CSVReader from 'react-csv-reader'
class App extends Component {
...
render() {
return (
)
}
}
ReactDOM.render(
`
More complex example:
`javascript
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import CSVReader from 'react-csv-reader'
class App extends Component {
...
const papaparseOptions = {
header: true,
dynamicTyping: true,
skipEmptyLines: true,
transformHeader: header =>
header
.toLowerCase()
.replace(/\W/g, '_')
}
render() {
return (
label="Select CSV with secret Death Star statistics"
onFileLoaded={this.handleForce}
onError={this.handleDarkSideForce}
parserOptions={papaparseOptions}
inputId="ObiWan"
inputName="ObiWan"
inputStyle={{color: 'red'}}
/>
)
}
}
ReactDOM.render(
`
| Name | Type | Default | Description |
| ------------- | --------------- | ------------------------ | -------------------------------------------------------------------------------- |
| accept | string | .csv, text/csv | File type accepted by file input. |csv-reader-input
| cssClass | string | | A CSS class to be applied to the wrapper element. |csv-input
| cssInputClass | string | | A CSS class to be applied to the element. |csv-label
| cssLabelClass | string | | A CSS class to be applied to the
When the file has been loaded, it will be parsed with PapaParse from a CSV formatted text to a matrix of strings or a list of objects (using header option).onFileLoaded
That parsed data is returned to the parent component with function (it will be passed as an argument).onFileLoaded
The second argument to will be an object with infos about loaded file.
`typescript`
// data: PapaParse.ParseResult.data
// fileInfo: IFileInfo
onFileLoaded: (data: Array
For type definitions, see here.
This packages uses jest for unit tests and snapshot testing.
To run the tests:
`sh`
yarn test
Automated accessibility tests are run with jest-axe`.
Please follow our convention on commits format.