Skip to content
Open source · MIT · net10.0 / net11.0

State management for Blazor,
minus the ceremony.

Write one [BlexState] field and one [BlexAction] method. A Roslyn source generator writes the reactive properties, the batched dispatch, the JSON snapshots and the loading and error lifecycle of your effects - and every action streams into the Redux DevTools with time travel built in.

dotnet add package Bit.Blex
CounterStore.cs
[BlexStore(Name = "counter", Persist = true)]
public partial class CounterStore
{
    [BlexState] private int _count;
    [BlexState] private int _step = 1;

    [BlexComputed] private int  ComputeDoubleCount() => Count * 2;
    [BlexComputed] private bool ComputeIsEven()      => Count % 2 == 0;

    [BlexAction] private void OnIncrement() => Count += Step;
    [BlexAction] private void OnDecrement() => Count -= Step;
}
Count loading
DoubleCount loading
IsEven loading

Persisted to localStorage - reload and the count survives. The Inspector at the bottom of the window shows every action.

Generated, not writtenproperties, dispatch and snapshots
Time travel built inRedux DevTools and in-app undo/redo
Effects with a lifecycleloading, error, cancellation, concurrency
Every hostServer, WebAssembly, Auto, Hybrid and MAUI

Capabilities

The Flux model, without the boilerplate

One observable state tree, named actions and a middleware pipeline - the parts of Flux that pay for themselves - with the action classes, reducers and feature registrations generated away.

Stores and computed state

A partial class with [BlexState] fields becomes a reactive store; [BlexComputed] methods become memoized properties that invalidate themselves.

Stores & state →

Batched, named actions

Every mutation inside an [BlexAction] folds into one notification, one render and one history entry, with its arguments captured as the payload - and a generated, typed descriptor to match it and dispatch it as data.

Actions →

Effects

[BlexEffect] generates XxxIsLoading, XxxError and CancelXxx(), with Latest, Drop and Queue concurrency, a built-in debounce, retries with backoff and timeouts.

Effects →

Server state

UseQuery caches what the server says: one request per key, background refetch when stale, invalidation after a change, mutations with optimistic rollback, and prerendered data handed to the browser instead of fetched twice.

Server state & queries →

Selectors

Subscribe a component to a projection and it re-renders only when that value changes - or let <BlexSelect> re-render just one fragment of it, and go across stores with CreateSelector.

Components & selectors →

Persistence

Persist = true and a provider: rehydrated on startup, debounced writes, versioned payloads with migrations, and sync across tabs.

Persistence →

Undo, redo and time travel

BlexHistory steps the state tree - or just the stores being edited - back and forth in the app; the DevTools bridge rewinds it from the browser extension.

Undo & redo →

In practice

See it in code

01

Write the store

A partial class marked [BlexStore]. Fields become reactive properties and OnXxx methods become public, recorded actions - the generator enforces the conventions at compile time.

Quick start →
[BlexStore(Name = "cart", Persist = true)]
public partial class CartStore
{
    [BlexState] private IReadOnlyList<CartLine> _lines = [];

    [BlexComputed] private decimal ComputeTotal() => Lines.Sum(l => l.Total);

    [BlexAction] private void OnAdd(CartLine line) => Lines = [.. Lines, line];
}
02

Register it, wrap the router

One call for Blex, one per store, and <BlexProvider> around the router - it registers the stores, restores persisted state and connects the DevTools.

Installation →
// Program.cs
builder.Services.AddBitBlexServices();
builder.Services.AddBitBlexStore<CartStore>();
builder.Services.AddBitBlexLocalStoragePersistence();

// App.razor
<BlexProvider>
    <Router AppAssembly="@typeof(App).Assembly">...</Router>
</BlexProvider>
03

Use it in a component

Subscribe(store) re-renders the component when the store changes and detaches itself on dispose - no StateHasChanged, nothing to unsubscribe.

Components & selectors →
@inherits BlexComponentBase
@inject CartStore Cart

<p>@Cart.Lines.Count items · @Cart.Total.ToString("C")</p>
<button @onclick="() => Cart.Add(new(...))">Add</button>

@code {
    protected override void OnInitialized() => Subscribe(Cart);
}

Comparison

Why not Fluxor?

Fluxor is the de-facto Redux library for Blazor, and it works - but a single counter costs a state class, an action class, a reducer and often an effect class, and there is no DevTools time travel.

TaskFluxorBlex
Define a piece of stateFeature + State classone [BlexState] field
Define an actionAction class + Reducer methodone [BlexAction] method
Derived statemanual selectors[BlexComputed], memoized
Async side-effectsEffect classes[BlexEffect] with generated loading and error
Persistencethird-partybuilt in, with debounce and migrations
Undo / redo✗BlexHistory
Redux DevTools time travel✗built in
Test helpers✗the Bit.Blex.Testing harness

Where to start

Choose your path

New to Blex?

A complete, reactive, time-travelable counter in three files and about twenty lines.

Quick start →

Coming from Fluxor?

What maps to what - stores for features, actions for reducers, effects for effects - and what is new.

The introduction →

Building with an AI agent?

This site is an MCP server: point your agent at /mcp and it runs the real generator over its stores instead of guessing.

Try the MCP server →

Questions

Frequently asked

Which hosting models does it support?

Blazor Server, WebAssembly, Auto and static server-side rendering, MAUI Blazor Hybrid and native .NET MAUI, on .NET 10 and 11. Prerendered store state is handed to the interactive render through PersistentComponentState, so a page does not flicker back to its defaults.

Do I need the Redux DevTools extension?

No. The bridge is off unless <BlexProvider EnableDevTools="true"> turns it on, and even then it disables itself when the extension is not there - as in a MAUI WebView. Turn it on in development only, so the state tree is never handed to an installed extension in production, and redact keys with RedactDevToolsKeys.

Is there reflection at runtime?

The store plumbing is generated at compile time, and a malformed store fails the build with a BLEX diagnostic. Snapshots go through System.Text.Json; for a trimmed or AOT publish, point BlexJson.Configure at a source-generated context of your state types.

Can I test a store without a browser?

Yes - stores, the manager and persistence never touch Blazor or JavaScript. A store tests like a plain object, and Bit.Blex.Testing adds a harness that records every action, its payload and the state after it.

Delete the boilerplate

One package, one service call, one provider - and a store is a field and a method.

dotnet add package Bit.Blex
An unhandled error has occurred. Reload 🗙