Blazored.LocalStorage
2.0.1
Prefix Reserved
See the version list below for details.
dotnet add package Blazored.LocalStorage --version 2.0.1
NuGet\Install-Package Blazored.LocalStorage -Version 2.0.1
<PackageReference Include="Blazored.LocalStorage" Version="2.0.1" />
paket add Blazored.LocalStorage --version 2.0.1
#r "nuget: Blazored.LocalStorage, 2.0.1"
// Install Blazored.LocalStorage as a Cake Addin #addin nuget:?package=Blazored.LocalStorage&version=2.0.1 // Install Blazored.LocalStorage as a Cake Tool #tool nuget:?package=Blazored.LocalStorage&version=2.0.1
Blazored LocalStorage
A library to provide access to local storage in Blazor applications
Important Notice For Server-side Blazor Apps
There is currently an issue with Server-side Blazor apps (not Client-side Blazor). They are unable to import static assets from component libraries such as this one.
You can still use this package, however, you will need to manually add the JavaScript file to your Server-side Blazor projects wwwroot
folder. Then you will need to reference it in your index.html
.
Alternatively, there is a great package by Mister Magoo which offers a solution to this problem without having to manually copy files.
Installing
You can install from Nuget using the following command:
Install-Package Blazored.LocalStorage
Or via the Visual Studio package manger.
Setup
First, you will need to register local storage with the service collection in your startup.cs file
public void ConfigureServices(IServiceCollection services)
{
services.AddBlazoredLocalStorage();
}
Usage (Client-side Blazor)
To use Blazored.LocalStorage in client-side Blazor, inject the ILocalStorageService
per the example below.
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@code {
protected override async Task OnInitAsync()
{
await localStorage.SetItemAsync("name", "John Smith");
var name = await localStorage.GetItemAsync<string>("name");
}
}
With client-side Blazor you also have the option of a synchronous API, if your use case requires it. You can swap the ILocalStorageService
for ISyncStorageService
which allows you to avoid use of async
/await
. For either interface, the method names are the same.
@inject Blazored.LocalStorage.ISyncStorageService localStorage
@code {
protected override void OnInit()
{
localStorage.SetItem("name", "John Smith");
var name = localStorage.GetItem<string>("name");
}
}
Usage (Server-side Blazor)
NOTE: Due to pre-rendering in server-side Blazor you can't perform any JS interop until the OnAfterRender
lifecycle method.
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@code {
protected override async Task OnAfterRenderAsync()
{
await localStorage.SetItemAsync("name", "John Smith");
var name = await localStorage.GetItemAsync<string>("name");
}
}
The APIs available are:
- asynchronous via
ILocalStorageService
:- SetItemAsync()
- GetItemAsync()
- RemoveItemAsync()
- ClearAsync()
- LengthAsync()
- KeyAsync()
- synchronous via
ISyncStorageService
:- SetItem()
- GetItem()
- RemoveItem()
- Clear()
- Length()
- Key()
Note: Blazored.LocalStorage methods will handle the serialisation and de-serialisation of the data for you.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Components.Browser (>= 3.0.0-preview4-19216-03)
NuGet packages (137)
Showing the top 5 NuGet packages that depend on Blazored.LocalStorage:
Package | Downloads |
---|---|
Blazored.LocalStorage.TestExtensions
A testing library to provide helper extensions for Blazored.LocalStorage |
|
Blauhaus.MVVM.Blazor
Package Description |
|
RapidCMS.UI
RapidCMS is a Blazor framework which allows you to build a responsive and flexible CMS purely from code. |
|
Arc4u.Standard.OAuth2.Blazor
Package Description |
|
Fluxor.Persist
Persists fluxor packages |
GitHub repositories (44)
Showing the top 5 popular GitHub repositories that depend on Blazored.LocalStorage:
Repository | Stars |
---|---|
dotnet-architecture/eShopOnWeb
Sample ASP.NET Core 8.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
|
|
MudBlazor/MudBlazor
Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
|
|
fullstackhero/dotnet-starter-kit
Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
|
|
fullstackhero/blazor-starter-kit
Clean Architecture Template for Blazor WebAssembly Built with MudBlazor Components.
|
|
Megabit/Blazorise
Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
|
Version | Downloads | Last updated |
---|---|---|
4.5.0 | 1,872,959 | 2/10/2024 |
4.4.0 | 1,408,443 | 8/14/2023 |
4.3.0 | 2,191,909 | 11/9/2022 |
4.3.0-preview.1 | 131,387 | 3/28/2022 |
4.2.0 | 2,190,686 | 2/4/2022 |
4.1.5 | 925,790 | 8/21/2021 |
4.1.4 | 1,879 | 8/21/2021 |
4.1.2 | 243,549 | 6/13/2021 |
4.1.1 | 85,092 | 5/15/2021 |
4.0.0 | 28,576 | 5/8/2021 |
3.0.0 | 837,544 | 7/23/2020 |
2.2.0 | 8,495 | 7/23/2020 |
2.1.6 | 132,125 | 5/21/2020 |
2.1.5 | 69,199 | 3/31/2020 |
2.1.4 | 2,007 | 3/30/2020 |
2.1.3 | 4,252 | 3/27/2020 |
2.1.1 | 133,246 | 9/25/2019 |
2.1.0 | 3,031 | 9/19/2019 |
2.0.14 | 614 | 9/17/2019 |
2.0.13 | 1,097 | 9/5/2019 |
2.0.12 | 2,603 | 8/19/2019 |
2.0.11 | 896 | 8/14/2019 |
2.0.10 | 419 | 8/14/2019 |
2.0.9 | 387 | 8/14/2019 |
2.0.8 | 401 | 8/13/2019 |
2.0.7 | 1,020 | 7/27/2019 |
2.0.6 | 418 | 7/25/2019 |
2.0.5 | 416 | 7/25/2019 |
2.0.3 | 381 | 7/25/2019 |
2.0.2 | 1,200 | 6/13/2019 |
2.0.1 | 2,077 | 5/31/2019 |
2.0.0 | 3,243 | 4/19/2019 |
1.2.1 | 2,274 | 3/15/2019 |
1.2.0 | 1,903 | 3/13/2019 |
1.1.0 | 1,936 | 3/9/2019 |
1.0.4 | 1,823 | 3/9/2019 |
1.0.3 | 1,884 | 3/4/2019 |
1.0.2 | 1,816 | 3/2/2019 |
1.0.1 | 2,105 | 2/9/2019 |
1.0.0 | 2,185 | 1/30/2019 |