You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -70,10 +68,9 @@ We create a `<script>` tag with a `type="importmap"` attribute, and then define
70
68
inside of it as JSON. Later, in a `<script type="module">` tag, we can import these modules using bare specifiers,
71
69
similar to what you'd see in Node.
72
70
73
-
> **Note:** We use `?external=preact` in the example above as https://esm.sh will helpfully provide the
71
+
> **Important:** We use `?external=preact` in the example above as https://esm.sh will helpfully provide the
74
72
> module you're asking for as well as its dependencies -- for `htm/preact`, this means also providing a
75
-
> copy of `preact`. However, Preact and many other libraries need to be used as singletons (only a single
76
-
> active instance at a time) which creates a problem.
73
+
> copy of `preact`. However, Preact must be used only as a singleton with only a single copy included in your app.
77
74
>
78
75
> By using `?external=preact`, we tell `esm.sh` that it shouldn't provide a copy of `preact`, we can handle
79
76
> that ourselves. Therefore, the browser will use our importmap to resolve `preact`, using the same Preact
@@ -121,3 +118,37 @@ query parameter, but other CDNs may work differently.
121
118
}
122
119
</script>
123
120
```
121
+
122
+
## HTM
123
+
124
+
Whilst JSX is generally the most popular way to write Preact applications, it requires a build step to convert the non-standard syntax into something browsers and other runtimes can understand natively. Writing `h`/`createElement` calls by hand can be a bit tedious though with less than ideal ergonomics, so we instead recommend a JSX-like alternative called [HTM](https://github.com/developit/htm).
125
+
126
+
Instead of requiring a build step (though it can use one, see [`babel-plugin-htm`](https://github.com/developit/htm/tree/master/packages/babel-plugin-htm)), HTM uses [Tagged Templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates) syntax, a feature of JavaScript that's been around since 2015 and is supported in all modern browsers. This is an increasingly popular way to write Preact apps and is likely the most popular for those choosing to forgo a build step.
127
+
128
+
HTM supports all standard Preact features, including Components, Hooks, Signals, etc., the only difference being the syntax used to write the "JSX" return value.
0 commit comments