
Every Blazor component goes through a predictable lifecycle. Understanding these methods lets you load data at the right time and clean up resources properly.
protected override async Task OnInitializedAsync()
{
products = await Http.GetFromJsonAsync<List<Product>>("/api/products");
}protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeVoidAsync("initChart");
}
}Use the firstRender flag to avoid running JS interop on every re-render.
Reference:
TaskLoco™ — The Sticky Note GOAT