Struct StateUpdater<T>
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
The single state setter returned by UseState<T>(T). Accepts either a
replacement value (setValue(next)) or a functional
updater (setValue(prev => next)). The functional form always reads the latest committed
value, so it is safe to invoke from a closure captured by an earlier render (no stale-closure pitfall).
public readonly struct StateUpdater<T>
Type Parameters
TState type.
Remarks
A struct (no allocation) wrapping the two cached closures built once at slot creation. The wrapped closures are reference-stable across renders, so a captured StateUpdater<T> stays valid. Equal-value updates do not request a re-render (identity-based bailout).
Methods
- Equals(object?)
Indicates whether this instance and a specified object are equal.
- Equals(StateUpdater<T>)
Value equality over the two wrapped (reference-stable) delegates. Two setters for the same state slot are equal across renders, so a StateUpdater<T> placed in a dependency array stays stable (UseCallback / UseEffect deps do not spuriously change).
- GetHashCode()
Returns the hash code for this instance.
- Invoke(Func<T, T>)
Computes the next state from the latest committed value (
setValue(prev => next)). Reads the current value at invocation time, so it is safe to call from a stale closure.
- Invoke(T)
Replaces the state with
next.
Operators
- implicit operator Action<Func<T, T>>(StateUpdater<T>)
Implicit conversion to the functional-updater System.Action<T> of
Func<T, T>, for callers that want to pass theprev => nextform as a delegate.
- implicit operator Action<T>(StateUpdater<T>)
Implicit conversion to the direct value-setter System.Action<T> so the setter can be stored in / passed as an
Action<T>(e.g. a callback parameter) and invoked with value-call syntax. The returned delegate is the cached, reference-stable value-setter.