Skip to content

UseResource

method
cref: M:Microsoft.UI.Reactor.Hooks.UseResourceExtensions.UseResource``1(Microsoft.UI.Reactor.Core.RenderContext,System.Func{System.Threading.CancellationToken,System.Threading.Tasks.Task{``0}},Microsoft.UI.Reactor.Core.QueryCache,System.Object[],Microsoft.UI.Reactor.Hooks.ResourceOptions,Microsoft.UI.Reactor.Hooks.IHookDispatcher)

Learn more: Hooks, Effects

Summary

Runs an async fetch keyed on , returning an AsyncValue1` that tracks the fetch's lifecycle. The hook owns the cancellation token, stores results in , and re-renders when new results land.

Discussion

Sync-complete fast path. If returns an already-completed task, this call returns Data(result) on the same render, with no transient Loading flash.Dispatcher. The hook captures the dispatcher at registration time (DispatcherQueue.GetForCurrentThread()). In unit tests without a WinUI dispatcher, continuations run inline on the thread-pool thread that completed the fetch.