Gathering detailed insights and metrics for react-csv-importer
Gathering detailed insights and metrics for react-csv-importer
Gathering detailed insights and metrics for react-csv-importer
Gathering detailed insights and metrics for react-csv-importer
Uploader + CSV parser + raw file preview + UI for custom user column mapping, all in one
npm install react-csv-importer
Typescript
Module System
Node Version
NPM Version
TypeScript (87.28%)
SCSS (9.84%)
JavaScript (2.51%)
HTML (0.23%)
CSS (0.15%)
Total Downloads
767,536
Last Day
758
Last Week
12,070
Last Month
44,977
Last Year
348,430
MIT License
235 Stars
539 Commits
101 Forks
1 Watchers
2 Branches
8 Contributors
Updated on Jul 04, 2025
Latest Version
0.8.1
Package Id
react-csv-importer@0.8.1
Unpacked Size
362.00 kB
Size
76.54 kB
File Count
8
NPM Version
8.19.4
Node Version
16.20.0
Published on
May 21, 2023
Cumulative downloads
Total Downloads
Last Day
-8.8%
758
Compared to previous day
Last Week
-5.3%
12,070
Compared to previous week
Last Month
7%
44,977
Compared to previous month
Last Year
67.7%
348,430
Compared to previous year
3
52
This library combines an uploader + CSV parser + raw file preview + UI for custom user column mapping, all in one.
Use this to provide a typical bulk data import experience:
Try it in the live code sandbox
1# using NPM 2npm install --save react-csv-importer 3 4# using Yarn 5yarn add react-csv-importer
Make sure that the bundled CSS stylesheet (/dist/index.css
) is present in your app's page or bundle.
This package is easy to fork with your own customizations, and you can use your fork directly as a Git dependency in any of your projects, see below. For simple CSS customization you can also just override the built-in styling with your own style rules.
Render the React CSV Importer UI component where you need it in your app. This will present the upload widget to the user. After a file is selected and reviewed by the user, CSV file data is parsed in-browser and passed to your front-end code as a list of JSON objects. Each object will have fields corresponding to the columns that the user selected.
Large files (can be up to 1GB and more!) are parsed in chunks: return a promise from your data handler and the file reader will pause until you are ready for more data.
Instead of a custom CSV parser this library uses the popular Papa Parse CSV reader. Because the file reader runs in-browser, your backend (if you have one) never has to deal with raw CSV data.
1import { Importer, ImporterField } from 'react-csv-importer'; 2 3// include the widget CSS file whichever way your bundler supports it 4import 'react-csv-importer/dist/index.css'; 5 6// in your component code: 7<Importer 8 dataHandler={async (rows, { startIndex }) => { 9 // required, may be called several times 10 // receives a list of parsed objects based on defined fields and user column mapping; 11 // (if this callback returns a promise, the widget will wait for it before parsing more data) 12 for (row of rows) { 13 await myAppMethod(row); 14 } 15 }} 16 defaultNoHeader={false} // optional, keeps "data has headers" checkbox off by default 17 restartable={false} // optional, lets user choose to upload another file when import is complete 18 onStart={({ file, preview, fields, columnFields }) => { 19 // optional, invoked when user has mapped columns and started import 20 prepMyAppForIncomingData(); 21 }} 22 onComplete={({ file, preview, fields, columnFields }) => { 23 // optional, invoked right after import is done (but user did not dismiss/reset the widget yet) 24 showMyAppToastNotification(); 25 }} 26 onClose={({ file, preview, fields, columnFields }) => { 27 // optional, if this is specified the user will see a "Finish" button after import is done, 28 // which will call this when clicked 29 goToMyAppNextPage(); 30 }} 31 32 // CSV options passed directly to PapaParse if specified: 33 // delimiter={...} 34 // newline={...} 35 // quoteChar={...} 36 // escapeChar={...} 37 // comments={...} 38 // skipEmptyLines={...} 39 // delimitersToGuess={...} 40 // chunkSize={...} // defaults to 10000 41 // encoding={...} // defaults to utf-8, see FileReader API 42> 43 <ImporterField name="name" label="Name" /> 44 <ImporterField name="email" label="Email" /> 45 <ImporterField name="dob" label="Date of Birth" optional /> 46 <ImporterField name="postalCode" label="Postal Code" optional /> 47</Importer>;
In the above example, if the user uploads a CSV file with column headers "Name", "Email" and so on, the columns will be automatically matched to fields with same labels. If any of the headers do not match, the user will have an opportunity to manually remap columns to the defined fields.
The preview
object available to some callbacks above contains a snippet of CSV file information (only the first portion of the file is read, not the entire thing). The structure is:
1{ 2 rawData: '...', // raw string contents of first file chunk 3 columns: [ // array of preview columns, e.g.: 4 { index: 0, header: 'Date', values: [ '2020-09-20', '2020-09-25' ] }, 5 { index: 1, header: 'Name', values: [ 'Alice', 'Bob' ] } 6 ], 7 skipHeaders: false, // true when user selected that data has no headers 8 parseWarning: undefined, // any non-blocking warning object produced by Papa Parse 9}
Importer component children may be defined as a render-prop function that receives an object with preview
and file
fields (see above). It can then, for example, dynamically return different fields depending which headers are present in the CSV.
For more, please see storybook examples.
You can swap the text used in the UI to a different locale.
import { Importer, deDE } from 'react-csv-importer';
// provide the locale to main UI
<Importer
locale={deDE}
// normal props, etc
/>
These locales are provided as part of the NPM module:
en-US
de-DE
it-IT
pt-BR
da-DK
tr-TR
You can also pass your own fully custom locale definition as the locale value. See ImporterLocale
interface in src/locale
for the full definition, and use an existing locale like en-US
as basis. For better performance, please ensure that the customized locale value does not change on every render.
Perform local git clone
, etc. Then ensure modules are installed:
1yarn
To start Storybook to have a hot-reloaded local sandbox:
1yarn storybook
To run the end-to-end test suite:
1yarn test
You can use your own fork of this library in your own project by referencing the forked repo as a Git dependency. NPM will then run the prepare
script, which runs the same Webpack/dist command as when the NPM package is published, so your custom dependency should work just as conveniently as the stock NPM version. Of course if your custom fixes could be useful to the rest of us then please submit a PR to this repo!
displayColumnPageSize
, displayFieldRowSize
)No vulnerabilities found.