title: Blazor - Compare Previous and Next State
body: <p>I have a table of students in Blazor, which is coming from an api, and I am also receiving a pushed data to update the students info which is basically the score upon a change in the database, the push is working fine and the score is being updated but I also want to change the background colour of the field that has been updated in the table upon a change in the score to red just the td tag for few sec, my code is as follow:</p>
  
  <pre><code>@foreach(var student in SS.GetStudents()){
       &lt;tr&gt;
            &lt;td&gt; student.name &lt;/&gt;
            &lt;td&gt; student.section &lt;/&gt;
            // trying to compare between the previous and next state
            var stud = SS.GetStuentsCopy().SingleOrDefault(s =&gt;s.Id == student.Id);
            var color = "";
            if(stud.score != student.score){
              color = red;
             }
            &lt;td class="@color"&gt; student.score &lt;/&gt;
       &lt;/tr&gt;
    }
  
     @code{
           [Inject]
           public StudentsStates SS { get; set;}
           public StudentsResponse Students { get; set; }
           protected override async Task OnInitializedAsync()
           { 
                // Subscribe to the StateChanged EventHandler
                 SS.StateChanged +=
                 SSAdvancedStateChanged;
  
            Students = await Service.GetStudents();
           // update the students and the copy together
            SS.UpdateStudents(Students)
            SS.UpdateStudentsCopy(Students)
  
  
         //upon receiving students updated score
                  hubConnection = new HubConnectionBuilder()
          .WithUrl(NavigationManager.ToAbsoluteUri("/studhub"))
          .Build();
  
          hubConnection.On&lt;StudentsResponse&gt;("ReceiveMessage", s =&gt;
          {
              // update the students after 3 sec update the copy
              SS.UpdateStudents(s);
  
  
             //Here the state is not being updated
             // unless there is a new push 
             // or the issue might be in rendering
             // FYI without the sleep also I can see the changes in the color
              System.Threading.Thread.Sleep(3000);
              SS.UpdateStudentsCopy(s);
  
          }
  
        }}
  </code></pre>
  
  <p>StudentsStates.cs</p>
  
  <pre><code>namespace Ctrl.Web.Data
  {
      public class StudentsStates
      {
  
          public StudentsResponse Students { get; set; }
          public StudentsResponse StudentsCopy { get; set; }
          public StudentsResponse GetStudents(){return Students;}
          public StudentsResponse GetStudentsCopy(){return StudentsCopy;}
          public void UpdateStudents(Students students){ Students = students;}
          public void UpdateStudentsCopy(Students students){ StudentsCopy = students;}
  
  }}
  </code></pre>
  
  <p>As I said above everything is working fine except when there is a multiple push in a sec, the first pushed student score's background color is being changed too fast, sometimes u won't even notice it because of the pushed data and state is being updated, what I want is to slow down the background color without effecting the next pushed student score or if there is a better approach to this scenario, your answers are highly appreciated.</p>