How do you share state between two components that are not in a parent-child relationship?
Last updated
Create a state container service holding the data plus an
event Actionraised on change, registered withAddScopedorAddSingleton.Both components
@injectit: one writes, the other subscribes inOnInitializedand callsStateHasChanged()in the handler.Unsubscribe in
Disposeto avoid memory leaks.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/answers/questions/1377680/blazor-default-template-application-issue
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-10.0
- https://medium.com/@Adem_Korkmaz/blazor-and-net-8-a-complete-guide-8a8886f02eef
- https://www.syncfusion.com/blogs/post/master-state-management-in-blazor