
For large applications, simple AppState services can become hard to manage. Fluxor is a popular Redux/Flux-inspired state management library for Blazor that brings unidirectional data flow.
// Install: dotnet add package Fluxor.Blazor.Web
builder.Services.AddFluxor(o =>
o.ScanAssemblies(typeof(Program).Assembly));
// App.razor:
<Fluxor.Blazor.Web.StoreInitializer />[FeatureState]
public record CounterState(int Count);
public static class CounterReducers
{
[ReducerMethod]
public static CounterState OnIncrement(
CounterState state, IncrementAction action)
=> state with { Count = state.Count + 1 };
}@inject IState<CounterState> CounterState
@inject IDispatcher Dispatcher
<p>Count: @CounterState.Value.Count</p>
<button @onclick="() => Dispatcher.Dispatch(new IncrementAction())">+</button>Reference:
TaskLoco™ — The Sticky Note GOAT