Table of Contents

Method UseOptimistic

Namespace
Velvet
Assembly
Velvet.Docs.dll

UseOptimistic<TState, TAction>(TState, Func<TState, TAction, TState>)

Returns the optimistic state and an addOptimistic action. Normally the returned state equals passthroughState. When addOptimistic(action) is invoked, applyOptimistic derives an optimistic state that is shown immediately (a re-render is requested) while the real update is in flight; once passthroughState changes (the real update lands), the optimistic override is discarded and the pass-through state is shown again.

public static (TState optimisticState, Action<TAction> addOptimistic) UseOptimistic<TState, TAction>(TState passthroughState, Func<TState, TAction, TState> applyOptimistic)

Parameters

passthroughState TState

The authoritative state. Shown when no optimistic update is outstanding.

applyOptimistic Func<TState, TAction, TState>

Pure reducer (currentState, action) => optimisticState. Must not be null.

Returns

(TState state, Action<TAction> dispatch)

2-tuple:

  • optimisticState: the optimistic state while an update is outstanding, otherwise the pass-through state.
  • addOptimistic: applies an optimistic action; the override is cleared when the pass-through state changes.

Type Parameters

TState

Optimistic state type.

TAction

Action / payload type passed to applyOptimistic.