JSFiddle - React, Tailwind, and code Playground

HTML

<div>set state here</div>
<button>go</button>

CSS

div {
  background-color: white;
}
.loading { background-color: orange; }
.finished { background-color: green; }
* {
  margin: 10px;
  padding: 10px;
}

JavaScript

$(function () {
  $("button").on('click', function (e) {
    var WAIT = 15; // play with this timeout ms value

    // set to "loading" state
    $("div").addClass('loading');

    // do the intensive calculations in a setTimeout thread
    setTimeout(function () {
      var j = 0, 
          MAX = 10000000;
      for(var i=0; i < MAX; i++) {
        j += Math.sin(i);
      }
      // set to "finished" state
      $("div").removeClass('loading').addClass('finished');
    }, WAIT);
  });
});