DEV Community

Kafui Alordo
Kafui Alordo

Posted on

Why the Composition API?

A short but concise note on why it is called or referred to as an Options API when you are torn apart on which of them to use.

Before we continue, note that the Composition API however is not meant to replace the Options API completely but rather, purely additive and only an alternative syntax for writing components in Vue.

  • They perform the same function

  • and can both be used concurrently in the same project.

Vue 3 is introduced as the New Default

But why was it introduced?

1. TypeScript Support
If you're gonna use TypeScript out of the box, then you are sure to leverage the Composition API instead.

2. Better Organization
Composition API provides better code layout and organization for our components than the Options API, if you're working on a more larger project.
remember the Composition API uses the setup() hook.

3. Better reusability
The Composition API offers a better code reusability than the mixins alternative the options API offers to handle the same logic. You can checkout mixins if you aren't familiar with it yet.

And that is it,

Though the Options API is completely optional, it can/or cannot be used per your preference and expert experience in writing Vue applications.

But I will advice as well to know how to use more the Options API by heart, so you better know when you're confident to go full Composition API in your next big project to clear any before doubts.

Happy Coding, Happy New Year!!!

Top comments (0)