What is the purpose of SetParametersAsync, and when would you override it instead of using the other lifecycle methods?
Last updated
SetParametersAsyncis the first lifecycle method: it assigns incomingParameterViewvalues to[Parameter]properties, then triggersOnInitialized/OnParametersSet.Override it only to intercept parameter assignment: validate or transform values, read them manually via
TryGetValue, or skip expensive work when nothing changed.You must call
base.SetParametersAsync(parameters)(or set properties yourself), otherwise the rest of the lifecycle never runs.
- https://www.telerik.com/blogs/blazor-basics-blazor-component-re-rendering
- https://blog.stackademic.com/mastering-the-blazor-lifecycle-when-to-use-each-method-without-losing-your-sanity-055c25d3728e
- https://www.learnblazor.com/component-lifecycle
- https://blazor-university.com/components/component-lifecycles/
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-10.0
- https://medium.com/@quentinsims89/blazor-component-communication-mastering-parameters-and-cascading-parameters-6ac093023956
- https://learn.microsoft.com/en-us/aspnet/core/blazor/performance/rendering?view=aspnetcore-10.0