728x90
LifeCycle 이 생각보다 복잡?하여 실재 로그를 찍어보았습니다.
@page "/lifecycletest"
<PageTitle>LifeCycleTest</PageTitle>
<h1>----------------------------------------------</h1>
<h1>LifeCycleTest</h1>
<button class="btn btn-primary" @onclick="IncrementCount">Click me (@currentCount)</button>
<h3>@logMessage</h3>
@code {
[Parameter]
public int Increment { get; set; } = 1;
private int currentCount = 0;
private string logMessage = string.Empty;
private void IncrementCount()
{
currentCount += Increment;
}
protected override void OnInitialized()
{
logMessage += "OnInitialized → ";
base.OnInitialized();
}
protected override Task OnInitializedAsync()
{
logMessage += "OnInitializedAsync → ";
return base.OnInitializedAsync();
}
public override Task SetParametersAsync(ParameterView parameters)
{
logMessage += "SetParametersAsync(ParameterView parameters) → ";
return base.SetParametersAsync(parameters);
}
protected override void OnParametersSet()
{
logMessage += "OnParametersSet → ";
base.OnParametersSet();
}
protected override Task OnParametersSetAsync()
{
logMessage += "OnParametersSetAsync → ";
return base.OnParametersSetAsync();
}
protected override void OnAfterRender(bool firstRender)
{
logMessage += "OnAfterRender(" + firstRender + ") → ";
base.OnAfterRender(firstRender);
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
logMessage += "OnAfterRenderAsync(" + firstRender + ") → ";
return base.OnAfterRenderAsync(firstRender);
}
protected override bool ShouldRender()
{
logMessage += "ShouldRender → ";
return base.ShouldRender();
}
}
결과
이 상태에서 버튼을 클릭하게되면 Render 관련 함수가 타게 됩니다.
결론순서
SetParametersAsync(ParameterView parameters)
→ OnInitialized
→ OnInitializedAsync
→ OnParametersSet
→ OnParametersSetAsync
→ (버튼클릭)
→ OnAfterRender(True)
→ OnAfterRenderAsync(True)
→ ShouldRender
[Source]
https://github.com/kei-soft/Blazor.AppTest/blob/master/Blazor.AppTest/Pages/LifeCycleTest.razor
참고
https://learn.microsoft.com/ko-kr/aspnet/core/blazor/components/lifecycle?view=aspnetcore-7.0
728x90
'C# > Blazor' 카테고리의 다른 글
[Blazor] PopUp 메세지 처리하기 - LiquidTechnologies.Blazor.ModalDialog (0) | 2023.01.03 |
---|---|
[Blazor] Blazored.Toast 사용하여 Toast Message 표시하기 (0) | 2023.01.02 |
[Blazor] EventCallback 이용하여 부모에게 값 전달하기 (0) | 2023.01.02 |
[Blazor] toast 메세지 표시하기 (0) | 2022.12.30 |
[Blazor] Required 항목 Disable 처리하기 (0) | 2022.12.29 |