DEV Community

Discussion on: Why you should be using Vue's new Composition API

Collapse
 
marzelin profile image
Marc Ziel • Edited

I know that this post isn't about async/about but I couldn't help it.
You create an async function but don't use await anywhere still working directly with promises. Either make it a normal function or use await:

const sendLike = async () => {
  isDisabled.value = true;
  likes.value++;
  try {                 // ↓ hardcoded postId, yikes
    await fetch('/api/post/1/likes', {
      method: 'POST'
    })
  } catch (e) {
    likes.value--;
  } finally {
    isDisabled.value = false;
  }
}
Enter fullscreen mode Exit fullscreen mode

Also, you should move this function to useLikes.js since it's part of the same feature set.