JSFiddle - React, Tailwind, and code Playground
JavaScript
function reduceWithDelay (fn, array, delay) {
return array.reduce((lastPromise,nextElement) =>
new Promise(resolve =>
lastPromise.then(()=>setTimeout(()=>{
fn(nextElement)
resolve();
}, delay))
), (new Promise(resolve=>resolve())));
}
const animation = reduceWithDelay(color=>document.body.style.backgroundColor=color, ['red','green'], 1000);
animation.then(()=>console.log('Animation fertig'));