Nested components typically bind data using *chained bind* as described in . Nested and unnested components can share access to data using a registered in-memory state container. A custom state container class can use an assignable to notify components in different parts of the app of state changes. In the following example: * A pair of components uses a state container to track a property. * One component in the following example is nested in the other component, but nesting isn't required for this approach to work. > [!IMPORTANT] > The example in this section demonstrates how to create an in-memory state container service, register the service, and use the service in components. The example doesn't persist data without further development. For persistent storage of data, the state container must adopt an underlying storage mechanism that survives when browser memory is cleared. This can be accomplished with `localStorage`/`sessionStorage` or some other technology. `StateContainer.cs`: ```csharp public class StateContainer { private string? savedString; public string Property { get => savedString ?? string.Empty; set { savedString = value; NotifyStateChanged(); } } public event Action? OnChange; private void NotifyStateChanged() => OnChange?.Invoke(); } ``` In `Program.cs` (Blazor WebAssembly): ```csharp builder.Services.AddSingleton(); ``` In `Program.cs` (Blazor Server) in ASP.NET Core 6.0 or later: ```csharp builder.Services.AddScoped(); ``` In `Startup.ConfigureServices` (Blazor Server) in versions of ASP.NET Core earlier than 6.0: ```csharp services.AddScoped(); ``` `Shared/Nested.razor`: ```razor @implements IDisposable @inject StateContainer StateContainer

Nested component

Nested component Property: @StateContainer.Property

@code { protected override void OnInitialized() { StateContainer.OnChange += StateHasChanged; } private void ChangePropertyValue() { StateContainer.Property = $"New value set in the Nested component: {DateTime.Now}"; } public void Dispose() { StateContainer.OnChange -= StateHasChanged; } } ``` `Pages/StateContainerExample.razor`: ```razor @page "/state-container-example" @implements IDisposable @inject StateContainer StateContainer

State Container Example component

State Container component Property: @StateContainer.Property

@code { protected override void OnInitialized() { StateContainer.OnChange += StateHasChanged; } private void ChangePropertyValue() { StateContainer.Property = "New value set in the State " + $"Container Example component: {DateTime.Now}"; } public void Dispose() { StateContainer.OnChange -= StateHasChanged; } } ``` The preceding components implement , and the `OnChange` delegates are unsubscribed in the `Dispose` methods, which are called by the framework when the components are disposed. For more information, see .