JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="doSomething()">
Click me
</button>
<div id="response">
Nothing happening yet
</div>
JavaScript
function myFirstFunction(event) {
document.getElementById('response').innerHTML = "First function...";
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('success');
//reject('error');
}, 2000);
});
}
function followupFunction() {
document.getElementById('response').innerHTML = "finished!";
}
function doSomething(event) {
document.getElementById('response').innerHTML = "doing something...";
return myFirstFunction(event).then(followupFunction);
};