The render function is one of the methods of the API
. It is used to render assets to the DOM. An asset can be a component, DOM node, markup or text. For a component, the Component.scope
of the component will be rendered. For markup, the markup is converted to an Element
. For text, the text is converted to a TextNode
.
render([options]);
- Type:
Object
- Required: No.
- Usage: Contains options for rendering assets.
- Reference:
options
A promise that resolves to undefined
.
{
assetType: string,
fileType: string,
target: Node | string,
asset: Node | string | Function | Object,
assets: Object,
placeholder: Element,
scope: Element,
props: Object,
replacer: Function
}
The type of asset to be rendered. All assets that are not DOM nodes will be converted to DOM nodes before they are rendered. It can have any of the following values:
"component"
: AComponent
."node"
: A DOMNode
."markup"
: HTML or XML markup."text"
: Any text content.
The type of file containing the asset. This property is considered only when asset
is a URL. It can be set to any of the following values:
"module"
: a JavaScript module (ESM)."text"
: HTML, XML or regular text file.
The Node
that the asset is going to replace when rendered. A CSS selector can be used. Using a CSS selector requires scope
to be included in options
.
The asset to be rendered. It can be any of the following:
- Component: A
Component
or aFunction
that returns a promise that resolves to aComponent
. - Node: A DOM
Node
. - Markup: HTML or XML.
- Text: Regular text.
Contains assets which can be referred to by property name using asset
.
Used as a placeholder for the Node
(asset) that is supposed to be rendered. This can be used to show a temporary UI component like a loader before the Node
is rendered. The placeholder gets rendered immediately. When the asset gets fetched and/or gets constructed, the asset is rendered.
The Element
that is used as the scope for a CSS selector (if target
is a string).
The props to be used in case the asset is a function and takes props.
A function used to replace the target
with the asset
. Refer to replacer
for more.