Skip to content

TypeScript & JSX

Nebula uses Preact for its lightweight JSX runtime. Preact is bundled for runtime, but TypeScript still needs local types.

Terminal window
npm install -D preact
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}

Use createElement or h from nebula-pdf-engine:

import { PdfEngine, Page, Text, createElement, h } from 'nebula-pdf-engine';
const tree = createElement(
Page,
{ size: 'A4', padding: 40 },
h(Text, { style: { fontSize: 20 } }, 'Hello Workspace!'),
);
const pdf = await engine.generate(tree);

ColumnDefinition<T> and TableProps<T> use key: keyof T:

type Row = { id: string; desc: string; amt: number };
const columns: ColumnDefinition<Row>[] = [
{ header: 'ID', key: 'id', width: 50 },
{ header: 'Description', key: 'desc', flex: 1 },
{ header: 'Amount', key: 'amt', width: 80, align: 'right' },
];