Walk through the standard Blazor component lifecycle, explaining the order of SetParametersAsync, OnInitialized, OnParametersSet, and OnAfterRender.
Last updated
Order:
SetParametersAsync(assigns[Parameter]values) →OnInitialized(once per lifetime) →OnParametersSet(first time and on every new parameter) → render →OnAfterRender.OnAfterRenderruns after the DOM updates withfirstRendertrue on the first pass, making it the safe spot for JS interop.ShouldRendercan suppress re-renders.An
awaitin the async hooks lets Blazor render an intermediate state, such as a loading indicator, before the task finishes.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-10.0
- https://www.coder000.com/post/blazor-component-lifecycle-and-state
- https://www.telerik.com/blogs/blazor-basics-blazor-component-re-rendering
- https://alexb72.medium.com/blazor-lifecycle-methods-oninitialized-onparametersset-and-onafterrender-36081a225d68
- https://blazor-university.com/components/component-lifecycles/
- https://medium.com/@shreyans_padmani/understanding-blazor-compontent-lifecycle-methods-in-c-69a9f9371c15
- https://www.thinktecture.com/en/blazor/blazor-components-lifecycle-is-not-always-straightforward/
- https://chrissainty.com/blazor-bites-component-lifecycle-methods/