Live Chat Icon For mobile
Live Chat Icon

Does StateHasChanged rerender all the components or only a particular component?

Platform: Blazor| Category: General

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 changes.


<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)

@code {
    List<int> list;
    const int cMaxNumbers = 10;

    protected void Generate()
        list = new List<int>(cMaxNumbers);
        for (int i = 0; i < cMaxNumbers; i++)

    protected void ChangeOneRow()
        list[0] = 123456;

In the above example, only the first list item will be re-rendered.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.