Table of Contents

Class Ref<T>

Namespace
Velvet
Assembly
Velvet.Docs.dll

Reference holder for an element or imperative handle. Receives a VisualElement-derived type via refCallback:, and can also hold any handle interface exposed by UseImperativeHandle.

public sealed class Ref<T> where T : class

Type Parameters

T

Type being referenced. Only constrained to class; not restricted to VisualElement.

Inheritance
object
Ref<T>

Constructors

Ref()

Creates an empty ref whose Current is null until assigned.

Properties

Current

Referenced target. null before mount and after unmount. Can be overwritten at any time via Set(T?).

Methods

Set(T?)

Directly overwrites the referenced target. Pass Set(null) to clear the reference (for example during cleanup).

SetElement(VisualElement)

Callback ref setter. Used as V.Button(refCallback: _ref.SetElement). Stores the element into Current; the returned Action is the cleanup that resets Current = null on detach. For T values not derived from VisualElement, element as T is always null, so this is primarily used for Element-node refs.