JSX essentials

New to Jeasx? This tour walks you through everything you need to know about jsx-async-runtime, the engine that turns your JSX into HTML. If you know JSX from React, most of it will feel familiar. The differences are small, but important.

Each step shows a short piece of code, the rendered result and the HTML the server sends to the browser.

1 Components are functions

A component is a plain function that receives its attributes as an object (the props) and returns JSX. Its name starts with an uppercase letter, so JSX can tell it apart from HTML tags like <p>.

Code
function Greeting({ name }) {
  return <p>Hello, {name}!</p>;
}

<Greeting name="Ada" />
Result

Hello, Ada!

HTML
<p>Hello, Ada!</p>

There are no hooks, no state and no virtual DOM: a component runs once and returns markup.

2 Children and fragments

Everything between the opening and closing tag of a component arrives as the children prop. Use a fragment <>…</> to return several elements without a wrapper.

Code
function Box({ title, children }) {
  return (
    <fieldset>
      <legend>{title}</legend>
      {children}
    </fieldset>
  );
}

<Box title="Fragments">
  <>
    <p>First</p>
    <p>Second</p>
  </>
</Box>
Result
Fragments

First

Second

HTML
<fieldset>
  <legend>Fragments</legend>
  <p>First</p>
  <p>Second</p>
</fieldset>

3 HTML attribute names

Unlike React, attributes keep their HTML names: class, for and onclick instead of className, htmlFor and onClick. Styles are plain strings, and true renders a boolean attribute, while false, null and undefined leave it out.

Code
<label for="email" class="label">Email</label>
<input
  id="email"
  type="email"
  style="max-width: 16rem"
  required={true}
  disabled={false}
/>
Result
HTML
<label for="email" class="label">Email</label>
<input
  id="email"
  type="email"
  style="max-width: 16rem"
  required
/>

4 Conditions and lists

JSX has no special template syntax: use &&, the ternary operator and .map() like in any JavaScript. Arrays are rendered item by item, and null, undefined and booleans render nothing.

Code
function Inbox({ messages }) {
  return (
    <div>
      {messages.length === 0 && <p>No messages.</p>}
      {messages.length > 0 && <p>{messages.length} new messages:</p>}
      <ul>
        {messages.map((message) => (
          <li>{message}</li>
        ))}
      </ul>
    </div>
  );
}

<Inbox messages={["Hi!", "Lunch?"]} />
Result

2 new messages:

  • Hi!
  • Lunch?
HTML
<div>
  <p>2 new messages:</p>
  <ul>
    <li>Hi!</li>
    <li>Lunch?</li>
  </ul>
</div>

No key props needed: the server just renders the list once.

5 Escaping and raw HTML

All text and attribute values are escaped, so user input can never inject markup. When you really need raw HTML (e.g. the doctype or trusted content from a CMS), wrap it in html().

Code
import { html } from "jsx-async-runtime";

const input = "<b>bold</b>";

<p>Escaped: {input}</p>
<p>Raw: {html(input)}</p>
Result

Escaped: <b>bold</b>

Raw: bold

HTML
<p>Escaped: &lt;b&gt;bold&lt;/b&gt;</p>
<p>
  Raw:
  <b>bold</b>
</p>

Never pass untrusted input to html(). Inline <script> and <style> content is escaped too, so wrap it in html() as well.

6 Async components

Here comes the twist: components can be async. Fetch data right where you need it, with no loaders, effects or suspense boundaries. The runtime waits for the component and renders the result in place.

Code
async function Weather({ city }) {
  const { temperature } = await loadWeather(city);
  return (
    <p>
      {city}: {temperature} °C
    </p>
  );
}

<Weather city="Berlin" />
Result

Berlin: 12 °C

HTML
<p>Berlin: 12 °C</p>

Promises work anywhere, as children and as attribute values, e.g. <img src={loadAvatarUrl()} />. If a component throws, the whole render fails; wrap risky parts in an error boundary to show a fallback instead (see Error boundaries).

7 Loading in parallel

Async components run one after another, in the order they appear. To load data at the same time, start the requests first and pass the promises as props. Each component awaits its own promise, the requests run in parallel, and the output keeps the order of your JSX.

Code
function Forecast() {
  // Both requests start right away and run at the same time.
  const berlin = loadWeather("Berlin");
  const paris = loadWeather("Paris");
  return (
    <ul>
      <City weather={berlin} />
      <City weather={paris} />
    </ul>
  );
}

async function City({ weather }) {
  const { city, temperature } = await weather;
  return <li>{city}: {temperature} °C</li>;
}
Result
  • Berlin: 12 °C
  • Paris: 15 °C
HTML
<ul>
  <li>Berlin: 12 °C</li>
  <li>Paris: 15 °C</li>
</ul>

8 Sharing data via 'this'

All components of one request share a context object as this. Store a value once and read it deep down the tree, without passing it through every component in between. In Jeasx, this also holds the request and reply.

Code
function Page() {
  this.user = "Ada";
  return <header><Nav /></header>;
}

function Nav() {
  return <nav><UserMenu /></nav>;
}

function UserMenu() {
  return <span>Signed in as {this.user}</span>;
}
Result
HTML
<header>
  <nav><span>Signed in as Ada</span></nav>
</header>

Components using this must be regular functions, not arrow functions. Each request gets a fresh context, so nothing leaks between visitors.

9 Rendering to a string

Jeasx renders your routes for you, but you can call the runtime yourself, e.g. in tests, for emails or in scripts. jsxToString returns the HTML as a string, or a promise if rendering had to wait. With await, both cases work the same.

Code
import { jsxToString } from "jsx-async-runtime";

const markup = await jsxToString(<Weather city="Paris" />);

<pre>{markup}</pre>
Result
<p>Paris: 15 °C</p>
HTML
<pre>&lt;p&gt;Paris: 15 °C&lt;/p&gt;</pre>

The result is plain text, so <pre> shows the escaped tags. Wrap it in html() only to insert trusted, pre-rendered markup, e.g. from a cache. To send markup while slow components are still loading, use jsxToStream instead (see Streaming HTML).

10 What else JSX renders

Besides strings, numbers and elements, the runtime renders many JavaScript values directly, so you rarely have to convert data before putting it into markup.

Children

Sets and other iterablesAny iterable renders its items, e.g. a Set, a Map or an iterator with helper methods like .map(). No need for Array.from().
Result
  • apple
  • banana
  • cherry
HTML
<ul><li>apple</li><li>banana</li><li>cherry</li></ul>
GeneratorsA generator function can be used as a component and yields its items one by one.
Result
  1. 0
  2. 1
  3. 1
  4. 2
  5. 3
  6. 5
  7. 8
  8. 13
HTML
<ol><li>0</li><li>1</li><li>1</li><li>2</li><li>3</li><li>5</li><li>8</li><li>13</li></ol>
Dates, URLs and errorsObjects with their own toString render as escaped text.
Result

Created at Fri Oct 30 2026 00:00:00 GMT+0000 (Coordinated Universal Time)
Fetched from https://www.jeasx.dev/?q=%3Cjsx%3E
Failed with Error: Something went wrong

HTML
<p>Created at Fri Oct 30 2026 00:00:00 GMT+0000 (Coordinated Universal Time)<br>Fetched from https://www.jeasx.dev/?q=%3Cjsx%3E<br>Failed with Error: Something went wrong</p>
BytesA Uint8Array or Buffer renders as UTF-8 text, e.g. a file read with fs.readFile() or the bytes of a fetch() response.
Result
Bytes are decoded as UTF-8 text: ✓ <b>escaped</b>
HTML
<pre>
Bytes are decoded as UTF-8 text: ✓ &lt;b&gt;escaped&lt;/b&gt;</pre>
BigInts and zeroBigInts render as numbers, and 0 isn't swallowed like in other templating languages.
Result

18446744073709551616 / 0

HTML
<p>18446744073709551616 / 0</p>
Functions and plain objectsLike null and booleans, empty arrays, functions and plain objects render nothing.
Result

HTML
<p></p>

Attributes

Objects and arrays as JSONPlain objects and arrays are encoded as JSON, e.g. to pass data to client-side scripts.
Result
Inspect me
HTML
<div data-config="{&quot;theme&quot;:&quot;dark&quot;,&quot;columns&quot;:3}" data-ids="[1,2,3]">Inspect me</div>
URLs and datesValues with their own toString use their string form.
Result
HTML
<a href="https://expo.jeasx.dev/essentials" data-date="Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)">Download</a>
Skipped valuesFunctions, null, false and objects without their own string form (e.g. a Set) are skipped, so an event handler never prints its source code.
Result
HTML
<button type="button">Click me</button>

Where to go next

You now know the essentials. Dive deeper with 'this' as context, Streaming HTML or Unit tests, or read the jsx-async-runtime documentation.