Member-only story

Blazor Lifecycle methods (OnInitialized, OnParametersSet and OnAfterRender)

Alex
9 min readDec 14, 2024

What is a Blazor Lifecycle method?

There are a few virtual methods (available in both synchronous and asynchronous) made available to Blazor components which can be overriden to alter the behaviour of our application. These virtual methods are ran at different times during a component’s lifetime.

The Blazor lifecycle methods that we will be going over today are the OnInitialized/OnInitializedAsync, OnParametersSet/OnParametersSetAsync and OnAfterRender/OnAfterRenderAsync. However, there are other Blazor lifecycle methods such as SetParametersAsync, Dispose and StateHasChanged but I will try to cover them in another article.

OnInitialized/OnInitializedAsync

These methods will be ran when a component is first initialized after the component receives its initial parameters in the SetParametersAsync method and have been assigned to the components [Parameter] property. This method is only ran once when the component is first created. Furthermore, if the parent component changes the child components parameters in the future then the OnInitialized* are not executed again.

OnParametersSet/OnParametersSetAsync

--

--

No responses yet