@sheetwrite/react wraps a Grid in a React component. It initializes WASM after
the component mounts on the client, so the page stays server-renderable.
Package @sheetwrite/react
Components Sheetwrite, SheetwriteGrid
Grid access Forwarded ref and onReady
Change events onGridChange prop
Install
$ npm install @sheetwrite/react
Import @sheetwrite/react/styles.css once in your app.
Mount a grid
Use Sheetwrite for the simple columns and defaultRows contract. Use
SheetwriteGrid when the host supplies a Workbook plus eager data or a
datasource.
import "@sheetwrite/react/styles.css" ;
type Row = { name : string ; amount : number };
Listen to changes
onGridChange reports committed Grid changes. onReady receives
{ grid, generation, reason } after the forwarded ref is assigned.
Resets and cleanup
Replacing a reset-sensitive input creates a new Grid generation. Destroy the
persistence and sync coordinators that you attached to the previous Grid, then
attach new ones in onReady. The lifecycle page
lists which inputs update in place and which reset.
Server rendering
Rendering the component on the server does not initialize WASM. In frameworks
that render on the server, mount it in a client component.
const Sheetwrite: <Row extends Record<string, CellScalar>, Id extends RowBridgeId = RowBridgeId>(props: SheetwriteProps<Row, Id> & {
ref?: ForwardedRef<Grid>;
}) => ReactElement const Sheetwrite : <
Row extends Record < string , CellScalar >,
Id extends RowBridgeId = RowBridgeId ,
>(
props : SheetwriteProps < Row , Id > & {
ref ?: ForwardedRef < Grid >;
},
) => ReactElement const Sheetwrite : <
Row extends Record <
string ,
CellScalar
>,
Id extends RowBridgeId =
RowBridgeId ,
>(
props : SheetwriteProps <
Row ,
Id
> & {
ref ?: ForwardedRef < Grid >;
},
) => ReactElement Convenience component for local object rows. It derives a single-sheet workbook from columns, defaultRows, and sheetName, initializes Sheetwrite, and owns the Grid through prop-driven resets and unmount cleanup. Pass a ref to access the live Grid; use SheetwriteGrid when the host already owns a workbook or datasource. Example import { Sheetwrite } from "@sheetwrite/react" ;
export function Sales () {
return < Sheetwrite
columns = {[{ key: "amount" , title: "Amount" , type: "number" }]}
defaultRows = {[{ amount: 12 }, { amount: 18 }]}
height = { 400 }
/>;
} See also SheetwriteGrid * See also /docs/frameworks/react/ API reference → interface GridReadyEvent interface GridReadyEvent interface GridReadyEvent Grid handle, generation, and reason published after adapter initialization. API reference → interface SimpleColumn<Row extends Record<string, CellScalar>> interface SimpleColumn < Row extends Record < string , CellScalar >> interface SimpleColumn < Row extends Record < string , CellScalar >> Column definition accepted by the adapters’ simple row-object API. API reference → interface Transaction interface Transaction interface Transaction Low-level Store transaction. epoch provides optional optimistic concurrency at the storage boundary. Calling Store.applyTransaction bypasses Grid read-only checks and Grid undo/redo history. Host-driven edits should use Grid.applyTransaction. Example import type { Store, SheetId, Transaction } from "@sheetwrite/core" ;
function setAmount ( store : Store , sheet : SheetId ) {
const transaction : Transaction = {
patches: [{ op: "set" , addr: { sheet, row: 0 , col: 0 }, value: { kind: "literal" , value: 25 } }],
};
return store. applyTransaction (transaction);
} See also Grid.applyTransaction API reference → type Row = {
name: string;
amount: number;
} type Row = {
name : string ;
amount : number ;
}; type Row = {
name : string ;
amount : number ;
}; name: string let name : string let name : string User-facing sheet name shown in tabs and workbook exports. API reference → SheetProps.columns: readonly SimpleColumn<Row>[] interface SheetProps {
columns : readonly SimpleColumn < Row >[];
} interface SheetProps {
columns : readonly SimpleColumn < Row >[];
} Exact column runs represented by every returned row. API reference → SheetProps.rows: readonly Row[] interface SheetProps {
rows : readonly Row [];
} interface SheetProps {
rows : readonly Row [];
} end-exclusive row range API reference → SheetProps.save: (transaction: Transaction) => void interface SheetProps {
save : ( transaction : Transaction ) => void ;
} interface SheetProps {
save : (
transaction : Transaction ,
) => void ;
} API reference → transaction: Transaction let transaction : Transaction let transaction : Transaction Operations that actually committed after policy and bounds filtering. API reference → SheetProps.onReady: (event: GridReadyEvent) => void interface SheetProps {
onReady : ( event : GridReadyEvent ) => void ;
} interface SheetProps {
onReady : (
event : GridReadyEvent ,
) => void ;
} Fires after the adapter publishes a ready Grid generation. API reference → function Sheet({ columns, rows, save, onReady }: SheetProps): JSX.Element function Sheet ({
columns ,
rows ,
save ,
onReady ,
} : SheetProps ) : JSX . Element function Sheet ({
columns ,
rows ,
save ,
onReady ,
} : SheetProps ) : JSX . Element API reference → columns: readonly SimpleColumn<Row>[] let columns : readonly SimpleColumn < Row >[] let columns : readonly SimpleColumn < Row >[] Exact column runs represented by every returned row. API reference → rows: readonly Row[] let rows : readonly Row [] let rows : readonly Row [] end-exclusive row range API reference → save: (transaction: Transaction) => void let save : ( transaction : Transaction ) => void let save : (
transaction : Transaction ,
) => void API reference → onReady: (event: GridReadyEvent) => void let onReady : ( event : GridReadyEvent ) => void let onReady : (
event : GridReadyEvent ,
) => void Fires after the adapter publishes a ready Grid generation. API reference → interface SheetProps interface SheetProps interface SheetProps columns: readonly SimpleColumn<Row>[] let columns : readonly SimpleColumn < Row >[] let columns : readonly SimpleColumn < Row >[] Ordered schema used to derive the component-owned sheet. API reference → defaultRows: readonly Row[] let defaultRows : readonly Row [] let defaultRows : readonly Row [] Rows converted to initial columnar data; missing column keys become null. API reference → height: string | number let height : string | number let height :
string | number Host height in CSS pixels for numbers or any CSS length string. API reference → onGridChange?: ((event: ChangeEvent) => void) | undefined onGridChange ?: (( event : ChangeEvent ) => void ) | undefined onGridChange ?: (( event : ChangeEvent ) => void ) | undefined Receives every committed Grid change, including its applied transaction. API reference → event: ChangeEvent let event : ChangeEvent let event : ChangeEvent API reference → ChangeEvent.transaction: Transaction interface ChangeEvent {
transaction : Transaction ;
} interface ChangeEvent {
transaction : Transaction ;
} Operations that actually committed after policy and bounds filtering. API reference → onReady?: ((event: GridReadyEvent) => void) | undefined onReady ?: (( event : GridReadyEvent ) => void ) | undefined onReady ?: (( event : GridReadyEvent ) => void ) | undefined Fires after the adapter publishes a ready Grid generation. API reference →