React
next-grid-react wraps next-grid-js/core as a React <NextGrid /> component with portal-mounted cell renderers and editors.
Installation
Section titled “Installation”npm install next-grid-react next-grid-js react react-domPeers: next-grid-js 0.1, react and react-dom 18 or 19.
import { useMemo, useRef } from 'react';import type { Grid } from 'next-grid-js/core';import { NextGrid } from 'next-grid-react';import 'next-grid-js/styles.css';
interface Order { id: string; customer: string; total: number;}
export function Orders({ orders }: { orders: Order[] }) { const grid = useRef<Grid<Order>>(null); const columnDefs = useMemo( () => [ { colId: 'customer', key: 'customer' as const, isSortable: true }, { colId: 'total', key: 'total' as const, cellDataType: 'number' as const }, ], [], );
return ( <NextGrid<Order> ref={grid} style={{ height: 400 }} columnDefs={columnDefs} rowData={orders} getRowId={(order) => order.id} onSortChanged={(event) => console.log(event.sort)} /> );}NextGrid accepts all GridOptions<T> except container, plus className, style, and id. Because it builds on next-grid-js/core, pass optional modules (ExportModule, ClipboardModule) in modules.
Props, Memoization & API Access
Section titled “Props, Memoization & API Access”- Keep
columnDefsstable withuseMemo: Columns whose definition object reference is unchanged keep their width, pin, order, and filter/sort state. - Mutable props:
columnDefs,columnGroups,defaultColDef,rowData,rowSource,datasource,viewportDatasource, hierarchy options,pivot,pivotColumnLimit,cellSpans,pinnedRows,pinnedTotals,theme, andon*callbacks update the live grid automatically. - Construction-only props: Changing props without setters (such as
density,localeText,rowHeight,modules) logs a development warning; pass a newkeyto remount intentionally. ref: Exposes the underlyingGrid<T>instance (nullbefore mount and after unmount).
Cell Renderers & Editors (Portals)
Section titled “Cell Renderers & Editors (Portals)”import { reactCellEditor, reactCellRenderer, type CellEditorProps, type CellRendererProps,} from 'next-grid-react';
function Total({ value }: CellRendererProps<Order>) { return <b>{String(value)}</b>;}
function TotalEditor({ value, setValue, commit }: CellEditorProps<Order>) { return ( <input defaultValue={String(value)} onChange={(e) => setValue(Number(e.target.value))} onBlur={commit} /> );}
const columnDefs = [ { colId: 'total', key: 'total' as const, isEditable: true, cellRenderer: reactCellRenderer(Total), cellEditor: reactCellEditor(TotalEditor), },];Components mount through React portals inside your component tree, preserving theme, router, and store context. reactCellRenderer, reactPinnedCellRenderer, and reactCellEditor return stable factory functions per component.
StrictMode & Server Rendering
Section titled “StrictMode & Server Rendering”- React
StrictMode: Double-mounting in development cleanly destroys the first grid instance before creating the second. - SSR / Next.js: Nothing is instantiated on the server;
<NextGrid />renders an empty host element on SSR and mounts on the client without hydration warnings (mark parent client components with'use client'in Next.js App Router).