Skip to content
Projets

À propos

Export dataset in react.

Développement web et applicatif

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

react-data-export

Export data from React to .xlsx and .csv.

Status: 1.0 is a from-scratch rewrite

  • 1.0 has a new API. It is rebuilt on javascript-excel 2.0, and its main entry has no <ExcelFile> / <ExcelSheet> / <ExcelColumn>. The 0.6 API ships only as the deprecated react-data-export/legacy entry: supported for all of 1.x, removed in 2.0. See Migrating from 0.x.

  • 1.0.0 is on npm's latest tag: npm install react-data-export. It has dataset export (exportDataset, exportWorkbook, useExcelExport, <ExcelExport>) and table export for an HTML <table> (exportTable, useTableExport, <ExportTableButton>), as specified in docs/api.md, built on javascript-excel 2.0's fromDataset, fromTable, writer and download. Coming from 0.x: the migration guide.

  • Big exports stay responsive. Exports run on the main thread. Since javascript-excel 2.0.0-alpha.7 (react-data-export requires 2.0.0 or later), the .xlsx writer returns to the event loop about every 16 ms, so the page keeps rendering and handling input during a large export, and abort() works while it runs. A worker option, which writes the file in a Web Worker on top of javascript-excel/worker, comes in a 1.x release after 1.0.0, not in 1.0 (docs/api.md §7).

    import { ExcelExport } from 'react-data-export';
    
    const people = {
      columns: [{ title: 'Name', key: 'name' }, { title: 'Joined', key: 'joined', type: 'date' }],
      data: [{ name: 'Ada', joined: new Date(2024, 0, 15) }],
    };
    
    <ExcelExport dataset={{ ...people, name: 'People', freezeHeader: true }} filename="people">
      Download people.xlsx
    </ExcelExport>
    
  • Try it in the browser: the playground runs the published 1.0 release.

  • 0.6.x stays on npm unchanged: latest is now 1.0.0, so a plain npm install react-data-export installs 1.0. Existing ^0.6.0 ranges keep resolving to 0.6.0, and npm install [email protected] keeps working. Nothing is unpublished or deprecated.

  • Legacy code and docs (0.x README, examples, Babel/Jest setup) live at the v0.6.0 tag.

Migrating from 0.x

Quick path: react-data-export/legacy. To run 0.x code on 1.0 without rewriting it yet, change the import to import ReactExport from 'react-data-export/legacy'. That entry has <ExcelFile>, <ExcelSheet>, <ExcelColumn>, the dataSet shape and xlsx-style styles. It writes the same files as 0.6.0, without 0.6's bugs: one download under StrictMode, and real CSV. It's deprecated: supported for all of 1.x, removed in 2.0, with one development warning. See the guide's quick path.

The migration guide shows every 0.x pattern next to its 1.0 code: ExcelFile + ExcelSheet + ExcelColumn, dataSet with xSteps/ySteps, hideElement, element, fileExtension, and the xlsx-style cell styles (with a converter). It also lists every intentional behaviour difference. The most common change:

// 0.x
<ExcelFile filename="employees" element={<button>Download</button>}>
    <ExcelSheet data={employees} name="Employees">
        <ExcelColumn label="Name" value="name"/>
        <ExcelColumn label="Marital Status" value={(col) => col.is_married ? "Married" : "Single"}/>
    </ExcelSheet>
</ExcelFile>
// 1.0
import { ExcelExport } from 'react-data-export';

const employees = [{ name: 'Monika', is_married: false }];

export const Download = () => (
  <ExcelExport
    filename="employees"
    dataset={{
      name: 'Employees',
      columns: [
        { title: 'Name', key: 'name' },
        { title: 'Marital Status', value: (row: (typeof employees)[number]) => (row.is_married ? 'Married' : 'Single') },
      ],
      data: employees,
    }}
  >
    Download
  </ExcelExport>
);

Things to know before you switch:

  • <ExcelColumn> headers are now bold, and 0.x's 80 px default column width is gone.
  • Dates are written in local time; 0.x converted them as UTC.
  • fileExtension is replaced by format: 'xlsx' | 'csv'. 0.6 saved an xlsx package even for csv, txt, xls and html.
  • Styles use javascript-excel's keys (font.size, fill: 'FF0000', …), and invalid values throw INVALID_STYLE.

0.6.x stays on npm unchanged (npm install [email protected]) if you're not ready to move.

TypeScript support

Types ship with the package (.d.ts for import, .d.cts for require). CI type-checks a consumer project against the packed tarball, in strict mode with skipLibCheck: false.

Supported: TypeScript 5.0 and later, with moduleResolution node16, nodenext (ESM and CommonJS consumers) or bundler. Every minor from 5.0 to 5.9, plus 6.0 and 7.0, is tested with @types/react 18 and 19. If the 1.0 API ever needs a newer TypeScript, this floor and the CI matrix will change together.

Repository layout

packages/react-data-export/   the published library (TypeScript, ESM + CJS + .d.ts)
apps/playground/              Vite + React 19 dev sandbox, tested in CI (the public playground is
                              securedeveloper/react-data-export-playground)
scripts/                      tarball smoke test and CI helpers

Development

Development needs Node ^22.22.2 || ^24.15.0 || >=26 (the strictest dev-tool floor, from jsdom; tsdown needs 22.18+). The published package declares Node >= 22 and has no Node-specific code.

npm ci
npm run typecheck
npm test
npm run build      # library (tsdown) + playground (Vite)
npm run smoke      # packs the library and checks ESM import, CJS require and types
npm run consumer-ts -- --ts 5.0,7.0 --react 19   # consumer type-check matrix (see TypeScript support)

CI runs the tests on Node 22 and 24 against React 17, 18 and 19. To try another React major locally: node scripts/use-react.mjs 17 (it rewrites dev ranges and node_modules; restore with git checkout -- package-lock.json '*/*/package.json' && npm ci).

Releasing

Versions are managed with Changesets. Merging a pull request that bumps the version publishes it to npm. See RELEASING.md.

License

MIT

Explorer des projets similaires

Chargement…