API
The opjsx tagged-template function.
The package exports a single function.
opjsx
function opjsx(
strings: TemplateStringsArray,
...values: unknown[]
): ReactElement | null;Used as a tagged template, it parses the markup and renders it to React elements:
import { opjsx } from "opjsx";
const el = opjsx`
&div.box
&h1
Title
`;- Returns a
ReactElement, ornullfor empty input. - Interpolations (
${…}) become real props/children: a lone interpolation keeps its JS type; nestedopjsxresults and arrays of them are passed through as children.
Pipeline
Internally, opjsx is render(parse(template)):
- parse — template text → a JSON element tree (
{ tag: { ...props, children } }), with${…}preserved as placeholders then substituted back as values. - render — the tree is walked into
React.createElementcalls. Values that are already React elements (e.g. nestedopjsxfrom a.map()) pass through unchanged.
Notes
- React is a peer dependency; opjsx adds no runtime React of its own.
- Parsing happens on each render. For hot paths, memoize the component as usual.