Blazor Component

72 Views Asked by At

Please find my Blazor component here, I need to loop through the list one time only.

How can I prevent to go through the loop after changing the text value to save time?

When I debug it, I find each time I change text value it loops again this affects on page performance badly.

<input type="text" value="@num" />
<button type="button" @onclick="UpdateValue">Update TextBox </button> 
<br />
@foreach(int x in lst)
{
 @x
 <br />
}
@code { 
 int num;
 List<int> lst = new List<int>();
 protected override async Task OnInitializedAsync()
 {
  lst.Add(1);
  lst.Add(2);
  lst.Add(3);
  lst.Add(4);
 }
 private void UpdateValue() => this.num = 10;
 // Task IHandleEvent.HandleEventAsync( //EventCallbackWorkItem callback, object arg) => callback.InvokeAsync(arg); 
}

I need to not loop again when I change text value

0

There are 0 best solutions below