JSFiddle - React, Tailwind, and code Playground
by sivcan
HTML
<html>
<head>
<title>Promises!</title>
</head>
<body>
<div id='result' />
</body>
</html>
JavaScript
let foo = { bar: (baz) => Promise.resolve(baz) };
let testFunction = () => {
return foo
.bar('baz')
.then((firstResult) => {
console.log(firstResult);
message = firstResult; // Set the value here
})
.then(() => foo
.bar('qux')
.then((secondResult) => {
message += secondResult;
document.getElementById('result').innerHTML = `Result after promise chain: <h2>${message}</h2>`;
}));
}
testFunction();