Method Component
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Component(Func<VNode>?, string?)
Embeds a function-style component ([Component] static VNode Foo()) into the VNode tree
as a child node. Props are read from Stores / Context via hooks,
so passing state/props through method arguments is not the supported pattern.
public static ComponentNode Component(Func<VNode>? body, string? key = null)
Parameters
bodyFunc<VNode>Delegate of a static method annotated with
[Component](e.g.FooComp.Render).keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode embedding the function-style component.
Component<TRef>(Func<VNode>?, Ref<TRef>, string?)
Embeds a function-style component with parent-to-child ref forwarding.
The child retrieves the ref via Hooks.ForwardedRef<THandle>()
and exposes it through Hooks.UseImperativeHandle.
public static ComponentNode Component<TRef>(Func<VNode>? body, Ref<TRef> componentRef, string? key = null) where TRef : class
Parameters
bodyFunc<VNode>Delegate of a static method annotated with
[Component].componentRefRef<TRef>The Ref<T> used for forwarding. Must not be null (use the refless overload when no ref is needed).
keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode with the parent-to-child ref wired through
componentRef.
Type Parameters
TRefHandle type that the parent receives via Ref<T>.
Component<TProps>(Func<TProps, VNode>, TProps, string?)
Embeds a function-style component that receives a single TProps
argument carrying the per-instance values (e.g. an item id plus a click handler).
Use this overload for V.List iteration / per-item callbacks where Context-based prop
distribution would require allocating a Provider node per item.
public static ComponentNode Component<TProps>(Func<TProps, VNode> body, TProps props, string? key = null)
Parameters
bodyFunc<TProps, VNode>Delegate of a static method annotated with
[Component]taking a singleTPropsparameter.propsTPropsThe props value to pass to
body.keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode.
Type Parameters
TPropsProps type. Use
sealed record(reference type) for value equality without boxing.
Remarks
Each parent render allocates a closure (DisplayClass + delegate) capturing
props. The fiber is reused across renders via body.Method
identity, and child hooks (UseCallback / UseMemo) can declare
props fields as deps to stabilize callbacks across renders.
TProps is stored as object on the fiber and compared
via object.Equals(object, object). Prefer a reference type
(sealed record) to obtain value equality without boxing; a record struct
boxes on every V.Component call.