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.
public static TSel UseStore<TStore, TSel>(Store<TStore> store, Func<TStore, TSel> selector, IEqualityComparer<TSel>? comparer = null)
Parameters
storeStore<TStore>Store instance to subscribe to. Must not be null.
selectorFunc<TStore, TSel>Pure projection from the store snapshot to the value the component cares about. Must not be null.
comparerIEqualityComparer<TSel>Equality comparer used to detect changes. The default applies the same
Object.isrule as theUseStatesetter, 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 ownEqualsso that a selector returning a freshrecord classinstance of stable content skips the re-render instead of triggering one. For a string selector, or a value-type selector other thanfloat/double— arecord structincluded — 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
TStoreStore snapshot type.
TSelSelected projection type returned to the component.