All Projects → Blazored → Localstorage

Blazored / Localstorage

Licence: mit
A library to provide access to local storage in Blazor applications

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Localstorage

Hermes
Client-side messaging channel for sending data from one browser tab to another
Stars: ✭ 111 (-73.88%)
Mutual labels:  hacktoberfest, localstorage
Msbuild.sdk.sqlproj
An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
Stars: ✭ 142 (-66.59%)
Mutual labels:  hacktoberfest, nuget
Menu
A JavaScript free menu library for Blazor and Razor Components applications.
Stars: ✭ 118 (-72.24%)
Mutual labels:  hacktoberfest, nuget
Secure Ls
🔒 Secure localStorage data with high level of encryption and data compression
Stars: ✭ 486 (+14.35%)
Mutual labels:  hacktoberfest, localstorage
Toast
A JavaScript free toast library for Blazor and Razor Component applications
Stars: ✭ 296 (-30.35%)
Mutual labels:  hacktoberfest, nuget
Jsql
jSQL is the "official" Javascript Query Language - A database written in Javascript for use in a browser or Node.
Stars: ✭ 85 (-80%)
Mutual labels:  hacktoberfest, localstorage
Sessionstorage
A library to provide access to session storage in Blazor applications
Stars: ✭ 132 (-68.94%)
Mutual labels:  hacktoberfest, nuget
Vuex Persistedstate
💾 Persist and rehydrate your Vuex state between page reloads.
Stars: ✭ 5,561 (+1208.47%)
Mutual labels:  hacktoberfest, localstorage
Mond
A scripting language for .NET Core
Stars: ✭ 237 (-44.24%)
Mutual labels:  hacktoberfest, nuget
Typeahead
Typeahead control for Blazor applications
Stars: ✭ 226 (-46.82%)
Mutual labels:  hacktoberfest, nuget
Quartznet
Quartz Enterprise Scheduler .NET
Stars: ✭ 4,825 (+1035.29%)
Mutual labels:  hacktoberfest, nuget
Modal
A powerful and customizable modal implementation for Blazor applications.
Stars: ✭ 406 (-4.47%)
Mutual labels:  hacktoberfest, nuget
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-71.53%)
Mutual labels:  hacktoberfest, nuget
Fluentvalidation
A library for using FluentValidation with Blazor
Stars: ✭ 184 (-56.71%)
Mutual labels:  hacktoberfest, nuget
32feet
Personal Area Networking for .NET
Stars: ✭ 395 (-7.06%)
Mutual labels:  hacktoberfest, nuget
Strongbox
Strongbox is an artifact repository manager.
Stars: ✭ 412 (-3.06%)
Mutual labels:  hacktoberfest, nuget
Digitalocean Cloud Controller Manager
Kubernetes cloud-controller-manager for DigitalOcean (beta)
Stars: ✭ 418 (-1.65%)
Mutual labels:  hacktoberfest
Microorm.dapper.repositories
CRUD for Dapper
Stars: ✭ 424 (-0.24%)
Mutual labels:  nuget
Advanceddlsupport
Delegate-based C# P/Invoke alternative - compatible with all platforms and runtimes.
Stars: ✭ 419 (-1.41%)
Mutual labels:  hacktoberfest
Tilex
Today I Learned
Stars: ✭ 418 (-1.65%)
Mutual labels:  hacktoberfest

Blazored LocalStorage

A library to provide access to local storage in Blazor applications

Build & Test Main

Nuget

Installing

You can install from NuGet using the following command:

Install-Package Blazored.LocalStorage

Or via the Visual Studio package manager.

Setup

You will need to register the local storage services with the service collection in your Startup.cs file in Blazor Server.

public void ConfigureServices(IServiceCollection services)
{
    services.AddBlazoredLocalStorage();
}

Or in your Program.cs file in Blazor WebAssembly.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");

    builder.Services.AddBlazoredLocalStorage();

    await builder.Build().RunAsync();
}

Configuration

The local storage provides options that can be modified by you at registration in your Startup.cs file in Blazor Server.

public void ConfigureServices(IServiceCollection services)
{
    services.AddBlazoredLocalStorage(config =>
        config.JsonSerializerOptions.WriteIndented = true);
}

Or in your Program.cs file in Blazor WebAssembly.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");

    builder.Services.AddBlazoredLocalStorage(config =>
        config.JsonSerializerOptions.WriteIndented = true);

    await builder.Build().RunAsync();
}

Usage (Blazor WebAssembly)

To use Blazored.LocalStorage in Blazor WebAssembly, inject the ILocalStorageService per the example below.

@inject Blazored.LocalStorage.ILocalStorageService localStorage

@code {

    protected override async Task OnInitializedAsync()
    {
        await localStorage.SetItemAsync("name", "John Smith");
        var name = await localStorage.GetItemAsync<string>("name");
    }

}

With Blazor WebAssembly you also have the option of a synchronous API, if your use case requires it. You can swap the ILocalStorageService for ISyncLocalStorageService which allows you to avoid use of async/await. For either interface, the method names are the same.

@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage

@code {

    protected override void OnInitialized()
    {
        localStorage.SetItem("name", "John Smith");
        var name = localStorage.GetItem<string>("name");
    }

}

Usage (Blazor Server)

NOTE: Due to pre-rendering in Blazor Server you can't perform any JS interop until the OnAfterRender lifecycle method.

@inject Blazored.LocalStorage.ILocalStorageService localStorage

@code {

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await localStorage.SetItemAsync("name", "John Smith");
        var name = await localStorage.GetItemAsync<string>("name");
    }

}

The APIs available are:

  • asynchronous via ILocalStorageService:

    • SetItemAsync()
    • GetItemAsync()
    • GetItemAsStringAsync()
    • RemoveItemAsync()
    • ClearAsync()
    • LengthAsync()
    • KeyAsync()
    • ContainsKeyAsync()
  • synchronous via ISyncLocalStorageService (Synchronous methods are only available in Blazor WebAssembly):

    • SetItem()
    • GetItem()
    • GetItemAsString()
    • RemoveItem()
    • Clear()
    • Length()
    • Key()
    • ContainsKey()

Note: Blazored.LocalStorage methods will handle the serialisation and de-serialisation of the data for you, the exception is the GetItemAsString[Async] method.

If you want to handle serialising and de-serialising yourself, serialise the data to a string and save using the SetItem[Async] method, as normal -- This method will not attempt to serialise a string value. You can then read out the data using the GetItemAsString[Async] method and de-serialise it yourself.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].