What are the three primary ways to pass data between components in Blazor (Parameters, Cascading Values, and State Services)?
Last updated
Blazor offers three main ways to move data between components, each for a different relationship: [Parameter] for direct parent-to-child, CascadingValue for a whole subtree, and DI state services for components that aren't related in the tree.
Parameters:
Public properties marked
[Parameter], set explicitly by the immediate parent's markup.Explicit and easy to trace; child-to-parent communication uses
EventCallback.
Cascading values:
Provided by
CascadingValueand consumed anywhere below with[CascadingParameter].Avoids parameter drilling for data many descendants need (theme, auth).
State services:
Injected classes registered in DI that hold shared data and raise change events.
The only clean option for unrelated components or app-wide/persistent state.
Choosing: Direct child: parameters. Shared subtree: cascading. No tree relationship or global: state service.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/?view=aspnetcore-10.0
- https://learn.microsoft.com/ca-es/aspnet/core/blazor/state-management/?view=aspnetcore-12.0
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/cascading-values-and-parameters?view=aspnetcore-10.0
- https://www.telerik.com/blogs/blazor-basics-component-parameters-state-management
- https://www.telerik.com/blogs/blazor-basics-html-forms-capturing-user-data
- https://www.oqtane.org/blog/!/91/passing-state-to-components-using-ssr-in-net-8
- https://medium.com/dotnet-new/state-management-in-blazor-applications-0890c20ca3b2
- https://medium.com/@quentinsims89/blazor-component-communication-mastering-parameters-and-cascading-parameters-6ac093023956