ctx.render()
Renders React elements, HTML strings, or DOM nodes into a specified container. If container is not provided, it defaults to rendering into ctx.element and automatically inherits the application's context, such as ConfigProvider and themes.
Use Cases
Note:
ctx.render()requires a rendering container. Ifcontaineris not passed andctx.elementdoes not exist (e.g., in pure logic scenarios without a UI), an error will be thrown.
Type Definition
Return Value:
- When rendering a React element: Returns
ReactDOMClient.Root, making it easy to callroot.render()for subsequent updates. - When rendering an HTML string or DOM node: Returns
null.
vnode Type Description
Examples
Rendering React Elements (JSX)
Rendering HTML Strings
Rendering DOM Nodes
Specifying a Custom Container
Multiple Calls Will Replace Content
Notes
- Multiple calls will replace content: Each
ctx.render()call replaces the existing content in the container rather than appending to it. - HTML string safety: Passed HTML is sanitized via DOMPurify to reduce XSS risks, but it is still recommended to avoid concatenating untrusted user input.
- Do not manipulate ctx.element directly:
ctx.element.innerHTMLis deprecated;ctx.render()should be used consistently instead. - Pass container when no default exists: In scenarios where
ctx.elementisundefined(e.g., within modules loaded viactx.importAsync), acontainermust be explicitly provided.
Related
- ctx.element - Default rendering container, used when no container is passed to
ctx.render(). - ctx.libs - Built-in libraries like React and Ant Design, used for JSX rendering.
- ctx.importAsync() - Used in conjunction with
ctx.render()after loading external React/component libraries on demand.

