h()
Creates a Virtual Node (VNode). A more user-friendly version ofcreateVNode() that allows omitting props when possible.
Type Signature:
The type of VNode to create. Can be:
- HTML tag name as string (e.g.,
'div','span') - Component object or constructor
- Special symbols:
Fragment,Text,Comment,Teleport,Suspense
Props and attributes to apply to the element or component. Can include:
- Standard HTML attributes
- Component props
- Event listeners (e.g.,
onClick,onInput) - Special properties (
key,ref, etc.)
null or omit when passing children without props.The children of the VNode. Can be:
- String or number (text content)
- Single VNode
- Array of VNodes
- Function (default slot for components)
- Object of slot functions (named slots for components)
Returns
A VNode object representing the virtual DOM node.Basic Usage
Element with Props
Nested Elements
Omitting Props
Component Usage
Named Slots
Fragments
The compiler converts templates to
createVNode() calls, not h(). Use h() only in manually written render functions.createVNode()
Creates a Virtual Node. This is the internal function used by the compiler. Useh() for manually written render functions.
Type Signature:
The type of VNode (string, Component, or symbol).
Props object including key, ref, and other attributes.
Children nodes (string, VNode, or array of VNodes).
Optimization hint for the patch process (compiler-generated).
Array of dynamic prop keys for optimization (compiler-generated).
Whether this VNode should be treated as a block node.
Returns
A VNode object.Usage
VNode Interface
The VNode interface represents a Virtual DOM node. Type Definition:Key Properties
The type of the VNode (tag name, component, or symbol).
Props and attributes including
key, ref, and event listeners.Child VNodes, text content, or slot functions.
Unique key for list rendering optimization.
Template ref for accessing the DOM element or component instance.
Reference to the actual DOM node (set during mounting).
Reference to the component instance (for component VNodes).
VNode Types
Special symbols and types used in VNode creation.Fragment
Symbol for creating fragment nodes (multiple root elements).Text
Symbol for creating text nodes.Comment
Symbol for creating comment nodes.isVNode()
Checks if a value is a VNode. Type Signature:The value to check.
Returns
true if the value is a VNode, false otherwise.
Example
cloneVNode()
Clones a VNode with optional props and children override. Type Signature:The VNode to clone.
Additional props to merge with the original props.
Whether to merge the ref. Defaults to
false.Returns
A new cloned VNode.Example
Cloning VNodes is useful for slot manipulation and higher-order component patterns.