a minimal implementation of JSX runtime element creation.
to use in esbuild's javascript build API, you will need to do one of the following options (or do both):
option 1 (preferred):
for JSX to work with your IDE's LSP, and for esbuild to automatically discover the hyperscript functions,
you will need to include the following two comment lines at the top of your .tsx script:
/** \@jsx h */ /** \@jsxFrag hf */
option 2 (no LSP support):
in the esbuild build options (BuildOptions), set jsxFactory = "h" and jsxFragment = "hf".
call createHyperScript with the signal context ctx as the argument
the returned tuple will contain 3 elements:
the first element should be named h (which is the name you declare as \@jsx h in option 1 or jsxFactory = "h" in option 2)
the second element should be named hf (which is the name you declare as \@jsxFrag hf in option 1 or jsxFragment = "hf" in option 2)
the third can be named anything
Example
// the `\@jsx h` comment comes here, but I can't show multiline comments in this documentation. // the `\@jsxFrag hf` comment comes here, but I can't show multiline comments in this documentation.
// when creating svgs or xml, you will have to change the DOM namespace, so that the correct kinds of `Node`s are created. namespaceStack.push("svg") const my_svg = <svgviewBox="0 0 200 200"> <gtransform="translate(100, 50)"> <texttext-anchor="middle">SVG says Hi!</text> <texty="25"text-anchor="middle">SVG stands for "SUGOI! Vector Graphics"</text> </g> </svg> namespaceStack.pop()
a minimal implementation of JSX runtime element creation.
to use in
esbuild
's javascript build API, you will need to do one of the following options (or do both):for JSX to work with your IDE's LSP, and for esbuild to automatically discover the hyperscript functions, you will need to include the following two comment lines at the top of your
.tsx
script:in the esbuild build options (
BuildOptions
), setjsxFactory = "h"
andjsxFragment = "hf"
.and now in your
.jsx
script, you should:createHyperScript
from this moduleContext
createHyperScript
with the signal contextctx
as the argumenth
(which is the name you declare as\@jsx h
in option 1 orjsxFactory = "h"
in option 2)hf
(which is the name you declare as\@jsxFrag hf
in option 1 orjsxFragment = "hf"
in option 2)Example