@burokku/react #
A React renderer for Burokku's UI tree. Host components are Burokku's elements
(div, flex, grid, text, and window), and React commits changes to them
directly through the app global.
import { useState } from "react";
import { createRoot } from "@burokku/react";
function Counter() {
const [count, setCount] = useState(0);
return (
<window title={`Clicked ${count}`}>
<flex style={{ padding: "16px", gap: "8px" }} onClick={() => setCount(count + 1)}>
<text style={{ fontSize: "16px", color: "#f6f6f7" }}>Clicked {count} times</text>
</flex>
</window>
);
}
createRoot().render(<Counter />);
example/react is a complete application, with the Rust binary that runs it.
Setup #
Point TypeScript's JSX at this package, so tags and their props are Burokku's:
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@burokku/react"
}
}
Bundle the application into one script for BurokkuBuilder::script, with
process.env.NODE_ENV defined, since QuickJS has no process. Vite's library
mode does this, and compiles JSX as tsconfig.json says:
import { defineConfig } from "vite";
export default defineConfig({
define: { "process.env.NODE_ENV": JSON.stringify("production") },
build: {
lib: {
entry: "src/main.tsx",
formats: ["iife"],
name: "App",
fileName: () => "app.js",
},
},
});
Rendering #
createRoot(container?, options?) renders into the app by default; the app
holds only window elements. It can also render into an element already in
the tree. As with React DOM, render commits on React's schedule, the first
render replaces whatever the container held, and unmount removes everything
synchronously. options takes React DOM's onUncaughtError, onCaughtError,
and onRecoverableError.
flushSync(callback) commits the updates callback schedules before
returning.
Props #
styletakes the camel-case keyssetStylesdoes, typed per tag. A key that becomesundefinedornullis removed from the element.- A prop named
onand a capital letter handles the event named by the rest in lower case:onPointerDownhandlespointerdown. SoonFocushandles the non-bubblingfocus, andonFocusInthe bubblingfocusin. Updates a handler makes take the priority React DOM gives that event, so a click's update commits before its task ends. refreceives the element.- Every other prop sets the attribute of its name, and
undefinedornullremoves it. Burokku readstabindexon any element, andtitle,width, andheighton windows.
Strings render as text nodes, which only a text or an input element may
hold; elsewhere, rendering one throws. An input's text is its value.
Not supported #
- Hiding elements: the UI tree has no
display: none, so the elements inside<Activity mode="hidden">, and inside a Suspense boundary that suspends again, stay visible. Only the text in them hides, including text that changes or goes in while they are hidden, and it shows again with them. <ViewTransition>, refs on fragments, portals, and hydration.