React Spreadsheet

0.10.1 · active · verified Sun Apr 19

React Spreadsheet is a library for building simple, customizable, and performant spreadsheet components within React applications. As of version 0.10.1, it focuses on providing a straightforward API for common use cases while maintaining flexibility. It has seen consistent updates, with recent releases introducing a new formula evaluation engine that supports cell dependencies and ranges (v0.8.0), and features like row/column selection (v0.7.0). The library differentiates itself by emphasizing 'Just Components™' and aiming for performance without virtualization, making it suitable for scenarios where a fully virtualized, complex spreadsheet might be overkill. It ships with TypeScript type declarations, ensuring a better developer experience with type introspection.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic setup of `react-spreadsheet`, showing how to render a simple spreadsheet component with initial data, including a basic formula, and handle changes to its content.

import React, { useState } from 'react';
import { Spreadsheet, CellBase } from 'react-spreadsheet';

interface MyData extends CellBase {
  value: string;
}

const initialData: MyData[][] = [
  [{ value: 'Header 1' }, { value: 'Header 2' }, { value: 'Header 3' }],
  [{ value: 'Row 1, Cell 1' }, { value: 'Row 1, Cell 2' }, { value: 'Row 1, Cell 3' }],
  [{ value: 'Row 2, Cell 1' }, { value: 'Row 2, Cell 2' }, { value: 'Row 2, Cell 3' }],
  [{ value: '=SUM(A2:B2)' }, { value: '=A2*B2' }, { value: 'Example Formula' }]
];

function MySpreadsheetApp() {
  const [data, setData] = useState<MyData[][]>(initialData);

  const handleDataChange = (newData: MyData[][]) => {
    console.log('Spreadsheet data changed:', newData);
    setData(newData);
  };

  return (
    <div style={{ padding: '20px', fontFamily: 'sans-serif' }}>
      <h1>Simple React Spreadsheet</h1>
      <p>Edit cells, including basic formulas like =SUM(A2:B2).</p>
      <Spreadsheet data={data} onChange={handleDataChange} />
    </div>
  );
}

export default MySpreadsheetApp;

view raw JSON →