Kind: Class
Source: src/jsx/base.ts
Part of: Jsx
JSXNode represents a JSX node and exposes conversion methods for rendering its contents. Call toString() to obtain rendered text, or call toStringToBuffer() when integrating with buffer-oriented output handling.
Implements: HtmlEscaped
Methods
| Method | Signature | Returns |
|---|---|---|
toString | toString() | `string |
toStringToBuffer | toStringToBuffer(buffer: StringBufferWithCallbacks) | void |
Properties
| Property | Type |
|---|---|
tag | `string |
props | Props |
key | string |
children | Child[] |
isEscaped | true |
Where it refuses work
JSXNodestops the work withErrorwhentypeof tag !== 'function' && !isValidTagName(tag).JSXNodestops the work withErrorwhenchildren.length > 0— “Can only set one ofchildrenorprops.dangerouslySetInnerHTML.”.JSXNodestops the work withErrorwhen!key.startsWith('on') && key !== 'ref'.
Diagram
mermaidgraph LR JSXNode --> ToString["toString(): string | Promise<string>"] JSXNode --> ToBuffer["toStringToBuffer(): void"] ToString --> Text["Rendered string"] ToBuffer --> BufferOutput["Buffer-oriented output"]
Usage
tsimport { JSXNode } from "./jsx/base";
async function renderNode(node: JSXNode): Promise<string> {
return await node.toString();
}
function writeNodeToBuffer(node: JSXNode): void {
node.toStringToBuffer();
}
AI Coding Instructions
- Handle
toString()as potentially asynchronous; useawaitwhen consuming its result. - Keep string rendering and buffer-oriented output separate by calling the method that matches the caller's output path.
- Do not assume
toStringToBuffer()returns rendered content; its return type isvoid. - Pass
JSXNodeinstances through rendering boundaries rather than converting them early when later output handling may differ.
Used by
2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (2)
title—src/jsx/intrinsic-element/components.ts:121StreamingContext—src/jsx/streaming.ts:30
Was this page helpful?