Overview
The Element type represents a renderable piece of UI in Dioxus. It’s the return type of all components and is built from VNodes (virtual nodes) that describe the structure of the DOM.Element Type
Element is a type alias for Result<VNode, RenderError>. Components return an Element, which can either be:
Ok(VNode)- A successfully rendered nodeErr(RenderError)- An error that propagates to the nearest error boundary
Creating Elements
VNode
VNode is the core virtual node type that represents a template with dynamic content.
Structure
Methods
VNode::empty()
Creates an element with no nodes that will be skipped during diffing.
VNode::placeholder()
Creates a template with a single placeholder node.
VNode::new()
Creates a new VNode with the specified template and dynamic content.
Template
TheTemplate struct describes the static structure of a UI tree. This is the core optimization in Dioxus - most UI is static and can be represented at compile time.
Structure
Fields
The list of root template nodes. Unlike React, Dioxus supports multiple roots.
Paths to each dynamic node relative to the template root.
Paths to each dynamic attribute relative to the template root.
TemplateNode
Represents a statically known node in the template.Variants
A static HTML element with tag name, namespace, attributes, and children.
A static text node.
A placeholder for a dynamic node. The
id indexes into the VNode’s dynamic_nodes array.DynamicNode
Represents runtime-determined nodes in the template.Variants
A child component with props and render function.
A dynamically generated text node.
A placeholder used by suspense and fragments that render nothing.
A list of VNodes created by conditional rendering or iterators.
VText
A text node with dynamic content.Methods
VText::new()
Creates a new text node.
Example Usage
See Also
- Component - Creating components
- Scope - Component context and state
- VirtualDom - The virtual DOM engine