When StateHasChanged is called, it runs change detection on the current component and its descendants. Blazor is clever enough to rerender the components that have changed.
<h3>StateHasChanged</h3>
<button class="btn btn-primary" @onclick="Generate">Generate List</button>
<button class="btn btn-primary" @onclick="ChangeOneRow">Change State</button>
@if (list != null)
{
@foreach (var item in list)
{
<li>@item</li>
}
}
@code {
List<int> list;
const int cMaxNumbers = 10;
protected void Generate()
{
list = new List<int>(cMaxNumbers);
for (int i = 0; i < cMaxNumbers; i++)
{
list.Add(i);
}
}
protected void ChangeOneRow()
{
list[0] = 123456;
StateHasChanged();
}
}
In the above example, only the first list will be re-rendered.
When StateHasChanged is called, it runs change detection on the current component and its descendants. Blazor is clever enough to rerender the components that have changed.
In the above example, only the first list will be re-rendered.
need an explanation for this answer? contact us directly to get an explanation for this answer