What is the difference between OnInitialized and OnInitializedAsync, and how does the renderer handle the component while the async task is still running?
Last updated
OnInitializedis synchronous for quick setup.OnInitializedAsyncreturns aTaskfor awaited I/O like data fetching. Both run once per component instance.At the first yielding
await, the renderer renders immediately with current state (show a loading placeholder). When the task completes it callsStateHasChangedand re-renders.Null-guard your markup, since it may render before the awaited data arrives.
- https://www.telerik.com/blogs/blazor-basics-blazor-component-re-rendering
- https://www.syncfusion.com/faq/what-is-the-purpose-of-component-initialization-methods-in-blazor
- https://blazor-university.com/components/component-lifecycles/
- https://github.com/dotnet/aspnetcore/issues/65665
- https://medium.com/dotnet-new/blazor-asynchronous-lifecycle-events-ba1d8c4216db
- https://www.esamatic.it/blog/blazor-component-lifecycle-events
- https://github.com/dotnet/aspnetcore/issues/44693
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-10.0