Why Composition API?

The Composition API solves the code organization problem that plagued large Vue 2 components. Instead of splitting logic by option type (data, methods, computed), you organize by feature concern.

Setting Up Reactive State

Use ref() for primitive values and reactive() for objects. Both create reactive references that trigger UI updates when changed.

Computed Properties

Use computed() to derive values from reactive state. Computed properties are cached and only recalculate when their dependencies change.

Lifecycle Hooks

Import hooks like onMounted, onUnmounted, and onUpdated directly from Vue. You can call them multiple times in a single setup function.