Table of Contents

Method UseStore

Namespace
Velvet
Assembly
Velvet.Docs.dll

UseStore<TStore, TSel>(Store<TStore>, Func<TStore, TSel>, IEqualityComparer<TSel>?)

Subscribes to an external Store via a selector. Must be used inside Render() only. The subscription is made in the passive effects of the commit, as UseSyncExternalStore<T>(Func<Action, Action>, Func<T>) makes its own, so a render that throws or suspends subscribes nothing; a change the store makes between the render and the subscription re-renders the component once it is made. A change re-renders it as a UseSyncExternalStore<T>(Func<Action, Action>, Func<T>) notification does: on the Urgent lane, inside a transition as well.

public static TSel UseStore<TStore, TSel>(Store<TStore> store, Func<TStore, TSel> selector, IEqualityComparer<TSel>? comparer = null)

Parameters

store Store<TStore>

Store instance to subscribe to. Must not be null.

selector Func<TStore, TSel>

Pure projection from the store snapshot to the value the component cares about. Must not be null.

comparer IEqualityComparer<TSel>

Equality comparer used to detect changes. The default applies the same Object.is rule as the UseState setter, branch for branch — see the remarks on StateUpdater<T>. Passing System.Collections.Generic.EqualityComparer<T>.Default therefore changes a non-string reference-type selector, where it swaps instance identity for the type's own Equals so that a selector returning a fresh record class instance of stable content skips the re-render instead of triggering one. For a string selector, or a value-type selector other than float/double — a record struct included — the default already gives the same answer as that comparer, so passing it changes nothing.

Returns

TSel

The selected value at the current store snapshot.

Type Parameters

TStore

Store snapshot type.

TSel

Selected projection type returned to the component.