Table of Contents

Method Use

Namespace
Velvet
Assembly
Velvet.Docs.dll

Use<T>(Func<UniTask<T>>, object?)

Declaratively fetches asynchronous data; while pending, throws a Velvet.FiberSuspendSignal to delegate the fallback to the nearest Suspense Boundary.

public static T Use<T>(Func<UniTask<T>> factory, object? resourceKey = null)

Parameters

factory Func<UniTask<T>>

Factory that returns a UniTask producing the value. Must not be null.

resourceKey object

Identity of the resource. When null, the factory delegate is the key.

Returns

T

The resolved value once the resource completes successfully.

Type Parameters

T

Resolved value type.

Remarks

The hook is keyed by the resource identity, not by a dependency array: the same resource returns the same result; presenting a different resource starts a new fetch. The optional resourceKey identifies the resource (compared by reference identity). When omitted, the factory delegate's identity is the key — a stable (cached) factory reuses the running resource, while a fresh closure each render is treated as a new resource. Pass a stable resourceKey (e.g. the query id) when the factory is a fresh closure but the resource is logically the same.

Use<T>(Func<CancellationToken, UniTask<T>>, object?)

CancellationToken-aware variant of Use<T>(Func<UniTask<T>>, object?). The token is cancelled when the resource is superseded (a new key) or the component unmounts; loader implementations are responsible for honoring it and aborting.

public static T Use<T>(Func<CancellationToken, UniTask<T>> factory, object? resourceKey = null)

Parameters

factory Func<CancellationToken, UniTask<T>>

Factory that receives a CancellationToken and returns a UniTask producing the value. Must not be null.

resourceKey object

Identity of the resource. When null, the factory delegate is the key.

Returns

T

The resolved value once the resource completes successfully.

Type Parameters

T

Resolved value type.