--- title: "State Management with Blazor using Fluxor (Part 1)" description: "Redux... redux ALL the things!" pubDate: 2020-06-26 heroImage: "/images/blog/dotnet-blazor-state-management/blazor_meme_part_1.png" tags: [dotnet] --- I'm gonna give it to you straight, uncensored, and off the cuff. Building reactive, fault tolerant, pleasant-to-use frontend single page applications in the modern web-based world is not an easy task; building _stateful_ applications, on top of all that, can be the most difficult part of frontend application engineering. Nowadays in the modern enterprise, frontend applications are more complicated than ever - managing user data, interacting with a plethora of APIs, all while allowing users to navigate from page to page and back again carrying what seems like (from an end user's perspective) a history of all their page interactions and application data they've inherently requested just by clicking buttons. To the untrained eye, this may seem like some form of complicated JavaScript dark magic, and alas, I ensure you for the most part, it is. However, sometime around the rise of React in the mid-2010s, Facebook developed a rather useful design pattern for managing frontend applications in a sane, predictable manner - [Flux](https://facebook.github.io/flux/docs/in-depth-overview). Using flux, Facebook (and by proxy, the React development community), pioneered a derivative of the subscriber pattern for the frontend, eventually leading to the development of the well-known [Redux](https://redux.js.org/) JavaScript library for building React applications. With the popularity of Redux and React together, state management adhering to the flux spec came into the mainstream, and a plethora of flux-based libraries, heavily influenced by redux, hit the market (as an Angular reformist, I'm quite partial to [NgRx](https://ngrx.io/)). With flux in our back pocket, state management on the frontend has become a tried and true design pattern for building rich, interactive applications that are predictable by nature and seemingly eliminate the infinite state machine that was the early days of JS on the web (if you think I'm joking, look at some JS written circa mid-1990's). The question then becomes, what about Blazor? I've put all my eggs in the Blazor basket, and one of the last things holding me back from full immersion was the existence of a flux-based library for the framework. Enter [Fluxor](https://github.com/mrpmorris/fluxor), an amazing open source library headed by [Peter Morris](https://github.com/mrpmorris) and the GitHub community, that provides an easy-to-use flux implementation for .NET Core and Blazor. In this series, I'll guide us as we develop a simple flux-based application using Fluxor with Blazor alongside [Redux DevTools](https://github.com/reduxjs/redux-devtools) (available for Chrome/Edge and Firefox), to manage everyone's favorite list - the todos. ## What we'll build For the completed source code of what we'll be building in the first part of this (at least planned, so far) three part series can be found [here](https://github.com/JoeyMckenzie/StateManagementWithFluxor/tree/feature/todos-part-1). With the help of the [JSON Placeholder](https://jsonplaceholder.typicode.com/guide.html) project, we'll be using their "API" (in quotes since it's not really a persistence server, simply just for making dummy calls) to build a simple CRUD application using the todo models from JSON Placeholder. ## Getting started To kick things off, let's go ahead and bootstrap a new Blazor WebAssembly project from your preferred project template provider. I'll be using Visual Studio throughout this series, but you're more than welcome to use Rider, VS Code, or just the command line. In Visual Studio, let's go ahead and hit up a `File > New Project` and select the `Blazor WebAssembly` project template. I'll name my project `StateManagementWithFluxor`, but you're welcome to pick a name of your choosing. Leaving the defaults, as we don't need any authentication or hosting from an ASP.NET Core server, let's go ahead and hit `Create`. With our project ready to roll within VS, let's add a package reference to `Fluxor.Blazor.Web` and `Fluxor.Blazor.Web.ReduxDevTools` using your preferred installation method: - Using the command line, `dotnet add package Fluxor.Blazor.Web` and `dotnet add package Fluxor.Blazor.Web.ReduxDevTools` - Using Package Manager with VS `Install-Package Fluxor.Blazor.Web` and `Install-Package Fluxor.Blazor.Web.ReduxDevTools` - Or, just simply add the package references through the NuGet GUI within VS Once we've got Fluxor added to the project, we'll need to add a few references to the library through our code to bring into scope. In our `index.html` file, let's add the required JavaScript bundle just above the closing `
` tag: #### index.html ```html