JSFiddle - React, Tailwind, and code Playground

JavaScript

var isValid = undefined;

alert(codeEditAddress());

function codeEditAddress() {
      test();
      return waitFor(function() { return isValid != undefined }, function(){return isValid});
}
                          
function test(){
       setTimeout(function(){isValid = true;}, 1000);

}
function waitFor(fnReady, fnCallback) {
            var check = function () {
                if (fnReady()) {
                    fnCallback();
                }
                else {
                    setTimeout(check, 100);  // wait another 100ms, and try again
                }
            };
            check();
}