DriDrood.BlazorStore
1.1.3
dotnet add package DriDrood.BlazorStore --version 1.1.3
NuGet\Install-Package DriDrood.BlazorStore -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DriDrood.BlazorStore" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DriDrood.BlazorStore" Version="1.1.3" />
<PackageReference Include="DriDrood.BlazorStore" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DriDrood.BlazorStore --version 1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DriDrood.BlazorStore, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DriDrood.BlazorStore@1.1.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DriDrood.BlazorStore&version=1.1.3
#tool nuget:?package=DriDrood.BlazorStore&version=1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
BlazorStore
Library for managing data in Blazor app. It re-render only those component, that uses changed data.
Using
To use this library you need to add nuGet package. Use NuGet package manager or following command:
dotnet add package DriDrood.BlazorStore
Build-in methods:
- Get - returns value, can throw null-reference
- GetOrDefault - returns value, if there are any null, returns default (in expressions there cannot be User?.Name)
- Set - updates value and re-render dependent components
- Add - add value to collection or dictionary and re-render dependent components
- Remove - remove value from collection or dictionary and re-render dependent components
Declaration
// This can be any data class
public class State
{
public User? User { get; set; }
public string? Url { get; set; }
}
// definition of store
public class Store : BlazorStore<State>
{
}
Usage in components
@inject Store Store
<div>@UserName</div>
@code
{
private string UserName
{
get => Store.GetOrDefault(s => s.User.Name, ChangedState);
set => Store.Set(s => s.User.Name, value);
}
}
Common Mistakes
// DO NOT USE THIS
private string UserName
{
get => Store.GetOrDefault(s => s.User, StateChanged)?.Name;
// this component will be re-rendered
// when any User property will change.
// It is useless
set
{
var user = Store.GetOrDefault(s => s.User);
user.Name = value;
}
// This will not re-render dependent component.
// Store data should be updated only through Set method.
set
{
var user = Store.GetOrDefault(s => s.User);
user.Name = value;
Store.Set(s => s.User, user);
}
// This will re-render all components that use any user
// property. It is useless
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.