Table of Contents

Method UseRef

Namespace
Velvet
Assembly
Velvet.Docs.dll

UseRef<T>()

Hook that returns the same Ref<T> across re-renders. On the first render, creates a new Ref<T>(), stores it in the fiber slot, and returns the same reference at the same position thereafter. Current stays null until it is assigned externally.

public static Ref<T> UseRef<T>() where T : class

Returns

Ref<T>

The fiber-scoped Ref<T> stored at this hook position.

Type Parameters

T

Reference target type.

UseRef<T>(Func<T>?)

Variant of UseRef<T>() that takes an initial factory. On the first render, invokes initialFactory and stores the result into Current, seeding the ref with a lazily-constructed value.

public static Ref<T> UseRef<T>(Func<T>? initialFactory) where T : class

Parameters

initialFactory Func<T>

Factory invoked once on first render to seed Current. Pass null to leave it unset.

Returns

Ref<T>

The fiber-scoped Ref<T> stored at this hook position.

Type Parameters

T

Reference target type.