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
Type Parameters
TReference 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
initialFactoryFunc<T>Factory invoked once on first render to seed Current. Pass null to leave it unset.
Returns
Type Parameters
TReference target type.