16

What libraries/techniques are available in Blazor for State management for webassembly (wasm).

It would be nice to know pros and cons of different approaches.

Neil
  • 7,482
  • 6
  • 50
  • 56

2 Answers2

22

There are several options:

Redux (Fluxor)

Redux/Flux pattern has become a leader in state management in JS word; so it would make sense to adopt this best practice.

Luckily there is already a Fluxor library that does just that; and it does have the most github stars 379; although it is still a relatively new area; so it remains to be seen what ends up being the most adopted approach later on.

There is a great intro video along with source code

Official docs:

  • State, actions, and reducers
  • Effects
  • Redux Dev Tools

An in depth article.

Blazor-State

Blazor-State

Pros: uses MediatR for messaging

See also

Overviews of State Management Approaches

https://chrissainty.com/mobile-blazor-bindings-state-management-and-data/

https://jonhilton.net/blazor-state-management/

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management

nice but mostly messaging: https://jasonwatmore.com/post/2020/07/30/aspnet-core-blazor-webassembly-communication-between-components

keywords: passing data between blazor wasm webassembly components child parent attributes events handling

Cfun
  • 8,442
  • 4
  • 30
  • 62
Neil
  • 7,482
  • 6
  • 50
  • 56
-9

A Blazor app is a C# app on top of the .Net BCL libraries. We don’t need to emulate what the JavaScript world has created to overcome its own deficiencies. C# can cache anything you want with static members.

Dean Chalk
  • 20,076
  • 6
  • 59
  • 90
  • 3
    I've had a fair number of people get mad at me when I tell them to do Blazory stuff in Blazor. – Bennyboy1973 Jun 05 '21 at 14:39
  • If you could provide an example of how to this technique of using static members for state management to accomplish what the OP desires (or point to some documentation or guidance on this) I would very much appreciate it, thanks! – paulguy Nov 16 '21 at 20:42
  • If you've used C# you've used static members. It works the same in blazor as it does in any other C# application – Dean Chalk Nov 18 '21 at 11:28
  • 3
    Nobody uses static members for things like state management. You don't have any isolation for your unit tests, and you have little control over the lifecycle of such values/instances. Dependency Injection is a much better approach. – Massimiliano Kraus Feb 04 '22 at 23:24
  • This kind of misses the point. One thing is using static members to store data, another is the pattern you use for doing so. Redux pattern and its principles is well established in web application development for variety of reasons and has proven to be solid and sound. The "persistance layer" - be it static members, browser storage or whatever else - is irrelevant in this case. What matters is the overal state management design and flow. – ofcoursedude Jun 09 '22 at 13:50