Table of Contents

Method UseMutableRef

Namespace
Velvet
Assembly
Velvet.Docs.dll

UseMutableRef<T>(T)

Hook that returns the same MutableRef<T> across re-renders, used as an instance-scoped mutable slot. Unlike UseRef<T>(), the type parameter is unconstrained so value types can be stored directly. On the first render, allocates new MutableRef<T>(initial) and stores it in the fiber slot; subsequent renders return the same instance. Writes to Current do not schedule a re-render.

public static MutableRef<T> UseMutableRef<T>(T initial)

Parameters

initial T

Initial value applied on the first render only.

Returns

MutableRef<T>

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

Type Parameters

T

Stored value type. May be a value type or a reference type.

UseMutableRef<T>(Func<T>)

Variant of UseMutableRef<T>(T) that takes a lazy factory. initialFactory is invoked only on the first render to seed Current; subsequent renders return the same instance without invoking the factory.

public static MutableRef<T> UseMutableRef<T>(Func<T> initialFactory)

Parameters

initialFactory Func<T>

Factory invoked once on first render to produce the initial value.

Returns

MutableRef<T>

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

Type Parameters

T

Stored value type. May be a value type or a reference type.