re: How to rewrite a callback function in Promise form and async/await form in JavaScript VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

Promise hell can't exist, that's why it's so nice!

const call_api = (url) => fetch(url).then(res => res.json())
const heaven = (url) => call_api(url).then(data => console.log(data))

heaven('/api/users')
  .then(() => heaven('/api/posts'))
  .then(([{ id }]) => heaven(`/api/posts/reactions?post=${id}`))
  .then(({ post: id }) => heaven(`/api/comments?post=${id}`))

See? It's really clean 😃

code of conduct - report abuse