Understanding the Razor component lifecycle
A Razor component, like any other object, possesses a lifecycle. It consists of a series of synchronous and asynchronous lifecycle methods that developers can override to perform additional operations during component initialization and rendering.
Refer to Figure 10.7 for an overview of the Razor component lifecycle:
Figure 10.7: Razor component lifecycle
In Figure 10.7, it is evident that we have the ability to add hooks during both the initialization and rendering phases. The methods listed below can be overridden to capture initialization events:
SetParametersAsync
OnInitialized
andOnInitializedAsync
OnParametersSet
andOnParametersSetAsync
SetParametersAsync
and OnInitializedAsync
are invoked only in the first render. OnParametersSet
Async
is called every time a parameter is changed.
The following methods can be overridden to customize rendering:
ShouldRender
OnAfterRender...