Skip to content

Commit f54efac

Browse files
committed
Add for v11 as well.
1 parent 0957c3a commit f54efac

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

pages/docs/manual/v11.0.0/jsx.mdx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ Below is a full list of everything you need in a generic JSX transform module, i
353353

354354
> You can easily copy-paste-and-adapt this to your needs if you're creating bindings to a JSX framework. Most often, all you'll need to change is what the `@module("") external` points to, so the runtime calls point to the correct JS module.
355355
356+
<CodeTab labels={["ReScript"]}>
357+
356358
```rescript
357359
// Preact.res
358360
/* Below is a number of aliases to the common `Jsx` module */
@@ -362,16 +364,16 @@ type component<'props> = Jsx.component<'props>
362364
363365
type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return>
364366
365-
@module("preact")
367+
@module("preact/jsx-runtime")
366368
external jsx: (component<'props>, 'props) => element = "jsx"
367369
368-
@module("preact")
370+
@module("preact/jsx-runtime")
369371
external jsxKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsx"
370372
371-
@module("preact")
373+
@module("preact/jsx-runtime")
372374
external jsxs: (component<'props>, 'props) => element = "jsxs"
373375
374-
@module("preact")
376+
@module("preact/jsx-runtime")
375377
external jsxsKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsxs"
376378
377379
/* These identity functions and static values below are optional, but lets
@@ -383,37 +385,53 @@ external array: array<element> => element = "%identity"
383385
external float: float => element = "%identity"
384386
external int: int => element = "%identity"
385387
external string: string => element = "%identity"
388+
external promise: promise<element> => element = "%identity"
386389
387390
/* These are needed for Fragment (<> </>) support */
388391
type fragmentProps = {children?: element}
389392
390-
@module("preact") external jsxFragment: component<fragmentProps> = "Fragment"
393+
@module("preact/jsx-runtime") external jsxFragment: component<fragmentProps> = "Fragment"
391394
392-
/* The Elements module is the equivalent to the ReactDOM module in React. This holds things relevant to _lowercase_ JSX elements. */
395+
/* The Elements module is the equivalent to the ReactDOM module in Preact. This holds things relevant to _lowercase_ JSX elements. */
393396
module Elements = {
394397
/* Here you can control what props lowercase JSX elements should have.
395398
A base that the React JSX transform uses is provided via JsxDOM.domProps,
396399
but you can make this anything. The editor tooling will support
397400
autocompletion etc for your specific type. */
398401
type props = JsxDOM.domProps
399402
400-
@module("preact")
403+
@module("preact/jsx-runtime")
401404
external jsx: (string, props) => Jsx.element = "jsx"
402405
403-
@module("preact")
406+
@module("preact/jsx-runtime")
404407
external div: (string, props) => Jsx.element = "jsx"
405408
406-
@module("preact")
409+
@module("preact/jsx-runtime")
407410
external jsxKeyed: (string, props, ~key: string=?, @ignore unit) => Jsx.element = "jsx"
408411
409-
@module("preact")
412+
@module("preact/jsx-runtime")
410413
external jsxs: (string, props) => Jsx.element = "jsxs"
411414
412-
@module("preact")
415+
@module("preact/jsx-runtime")
413416
external jsxsKeyed: (string, props, ~key: string=?, @ignore unit) => Jsx.element = "jsxs"
414417
415418
external someElement: element => option<element> = "%identity"
416419
}
417420
```
418421

422+
</CodeTab>
423+
419424
As you can see, most of the things you'll want to implement will be copy paste from the above. But do note that **everything needs to be there unless explicitly noted** or the transform will fail at compile time.
425+
426+
To enable this, you need to configure the `jsx` `module` in your `rescript.json`:
427+
428+
```json
429+
{
430+
"jsx": {
431+
"version": 4,
432+
"module": "Preact"
433+
}
434+
}
435+
```
436+
437+
_value "Preact" is the name of the module that implements the generic JSX transform._

0 commit comments

Comments
 (0)