Skip to content

jsx-html.ts#

View Markdown

Source

18 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

18 symbols 11 functions 2 interfaces 2 types 2 variables 1 modules 19 parameters 3 members 11 returns 4 examples

Reference#

variableconst ATTR_ALIASES: Record<string, string>React prop names whose HTML spelling is not the lowercased identifier.

React prop names whose HTML spelling is not the lowercased identifier.

Signature

const ATTR_ALIASES: Record<string, string>

View source

fneach<T>(items: T[], render: (item: T, index: number) => JSXNode): JSXNodeMaps over an array and renders each item.

Maps over an array and renders each item.

Signature

export function each<T>(items: T[], render: (item: T, index: number) => JSXNode): JSXNode

View source

Parameters

Returns

JSXNode

Examples

Example 1
{each(items, (item) => <li>{item.name}</li>)}
fnescapeHtml(str: string): stringEscapes HTML special characters to prevent XSS.

Escapes HTML special characters to prevent XSS.

Signature

function escapeHtml(str: string): string

View source

Parameters

  • str string

Returns

string
fnFragment({ children }: { children?: JSXChild }): JSXNodeFragment component - renders children without a wrapper element.

Fragment component - renders children without a wrapper element.

Signature

export function Fragment({ children }: { children?: JSXChild }): JSXNode

View source

Parameters

Returns

JSXNode
fnjsx(type: JSXElementType, props: JSXProps, _key?: string): JSXNodeCreates a JSX element. This is the core function called by the JSX transform.

Creates a JSX element. This is the core function called by the JSX transform.

Signature

export function jsx(type: JSXElementType, props: JSXProps, _key?: string): JSXNode

View source

Parameters

Returns

JSXNode
modulejsx-htmlCustom JSX Runtime for Static HTML Generation This module provides a JSX runtime that outputs static HTML strings. No R…

Custom JSX Runtime for Static HTML Generation

This module provides a JSX runtime that outputs static HTML strings. No React, no hydration, no client-side JavaScript - just pure HTML.

This is the implementation. The JSX transform imports it through the ./jsx-runtime and ./jsx-dev-runtime entry points, which are the subpaths jsxImportSource resolves. Keeping the implementation under its own name keeps those two entries from colliding with the shared bundle chunk.

View source

Examples

Example 1
// tsconfig.json or vite.config.ts
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@ox-content/vite-plugin"
  }
}

// MyComponent.tsx
export function Hero({ title }: { title: string }) {
  return (
    <section class="hero">
      <h1>{title}</h1>
    </section>
  );
}
typeJSXChild = string | number | boolean | null | undefined | JSXNode | JSXChild[]Valid JSX child types.

Valid JSX child types.

Signature

export type JSXChild = string | number | boolean | null | undefined | JSXNode | JSXChild[]

View source

typeJSXElementType = string | ((props: Record<string, unknown>) => JSXNode)JSX element type - either a string (intrinsic) or a function component.

JSX element type - either a string (intrinsic) or a function component.

Signature

export type JSXElementType = string | ((props: Record<string, unknown>) => JSXNode)

View source

interfaceJSXNodeJSX node - the result of JSX expressions.

JSX node - the result of JSX expressions.

Signature

export interface JSXNode

View source

Members

Properties
NameTypeDescription
__html string
interfaceJSXPropsProps with children.

Props with children.

Signature

export interface JSXProps

View source

Members

Indexable
[key: string]: unknown
Properties
NameTypeDescription
childrenoptional JSXChild
fnjsxs(type: JSXElementType, props: JSXProps, key?: string): JSXNodeCreates a JSX element with static children. Called by the JSX transform for ele…

Creates a JSX element with static children. Called by the JSX transform for elements with multiple children.

Signature

export function jsxs(type: JSXElementType, props: JSXProps, key?: string): JSXNode

View source

Parameters

Returns

JSXNode
fnraw(html: string): JSXNodeCreates raw HTML without escaping. Use with caution - only for trusted content.

Creates raw HTML without escaping. Use with caution - only for trusted content.

Signature

export function raw(html: string): JSXNode

View source

Parameters

  • html string

Returns

JSXNode

Examples

Example 1
<div>{raw('<strong>Bold</strong>')}</div>
fnrenderAttr(name: string, value: unknown): stringRenders an attribute value to a string.

Renders an attribute value to a string.

Signature

function renderAttr(name: string, value: unknown): string

View source

Parameters

  • name string
  • value unknown

Returns

string
fnrenderChildren(children: JSXChild): stringRenders children to HTML string.

Renders children to HTML string.

Signature

function renderChildren(children: JSXChild): string

View source

Parameters

Returns

string
fnrenderToString(node: JSXNode): stringRenders a JSX node to an HTML string.

Renders a JSX node to an HTML string.

Signature

export function renderToString(node: JSXNode): string

View source

Parameters

Returns

string
variableconst SVG_CAMEL_CASE = new Set(["viewBox"])SVG attributes that stay camelCase in HTML (they are case-sensitive).

SVG attributes that stay camelCase in HTML (they are case-sensitive).

Signature

const SVG_CAMEL_CASE = new Set(["viewBox"])

View source

fntoHtmlAttr(name: string): stringConverts a JSX/React prop name to the HTML attribute the runtime emits. HTML at…

Converts a JSX/React prop name to the HTML attribute the runtime emits.

HTML attributes are case-insensitive and conventionally lowercase (charSetcharset, tabIndextabindex). A few React names are not a lowercase of themselves (className, httpEquiv), and SVG names like viewBox must keep their case.

Signature

function toHtmlAttr(name: string): string

View source

Parameters

  • name string

Returns

string
fnwhen(condition: boolean, content: JSXNode): JSXNodeConditionally renders content.

Conditionally renders content.

Signature

export function when(condition: boolean, content: JSXNode): JSXNode

View source

Parameters

  • condition boolean
  • content JSXNode

Returns

JSXNode

Examples

Example 1
{when(isLoggedIn, <UserMenu />)}