REACT + CANVAS RENDERING RECIPE
Integrating Titan with Glide Data Grid
Glide Data Grid renders cells to an HTML5 Canvas at 60fps by invoking getCellContent([col, row]) on visible cells. Pairing Glide's canvas virtualizer with Titan's delta-driven WASM calculation engine gives you a complete Excel-grade spreadsheet in under 70 lines of React.
Step 01
Subscribe to Deltas
Cache change.cell.display and change.cell.value from onCellsChanged.
Step 02
Display vs. Edit Overlay
Pass displayData (computed result) and data (raw formula string) so double-clicking reveals the formula.
Step 03
Debounced Batch Edits
Flush rapid edits and multi-cell pastes through engine.setCells(queue).
Complete React Integration Component
Spreadsheet.jsx
React 18 + @glideapps/glide-data-grid
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { DataEditor, GridCellKind } from '@glideapps/glide-data-grid';
import { initTitan } from 'titan-engine';
export default function Spreadsheet() {
const [sheet, setSheet] = useState(null);
const [tick, setTick] = useState(0);
const outputs = useRef({});
const inputs = useRef({});
useEffect(() => {
initTitan().then((Titan) => {
const engine = new Titan();
const s = engine.addSheet("Sheet1");
engine.onCellsChanged((deltas) => {
for (const { row, col, cell } of deltas) {
outputs.current[row] ??= {};
inputs.current[row] ??= {};
outputs.current[row][col] = cell.display;
inputs.current[row][col] = cell.value;
}
setTick((t) => t + 1);
});
setSheet(s);
});
}, []);
const getCellContent = useCallback(([col, row]) => {
const display = outputs.current[row]?.[col] ?? "";
const raw = inputs.current[row]?.[col] ?? display;
return {
kind: GridCellKind.Text,
allowOverlay: true,
displayData: String(display),
data: String(raw),
};
}, [tick]);
const onCellEdited = useCallback(([col, row], newValue) => {
if (!sheet) return;
inputs.current[row] ??= {};
inputs.current[row][col] = newValue.data;
sheet.set({ row, col }, newValue.data);
}, [sheet]);
if (!sheet) return <div>Booting WASM…</div>;
return (
<DataEditor
columns={[{ title: "A", width: 120 }, { title: "B", width: 120 }, { title: "C", width: 140 }]}
rows={1000}
getCellContent={getCellContent}
onCellEdited={onCellEdited}
/>
);
}