JSFiddle - React, Tailwind, and code Playground
JavaScript
const one = () => new Promise((resolve) => {
return resolve(1)
});
const two = (val) => new Promise((resolve) => {
return resolve(val * 5);
})
const three = (val, val2) => new Promise((resolve) => {
return resolve(val + val2);
})
one().then((r) => {
//r is 1
console.log('r is 1:', r)
return r
})
//we pass the return value from the previous to the two function
.then(two)
.then((r) => {
//r is 1 * 5
console.log('r is 1 * 5:', r)
return three(r, 10)
})
.then((r) => {
//r is now 5 + 10
console.log('r is now 5 + 10:', r)
})