Performance: Creating a custom composable
MEDIUM IMPACT
This affects how efficiently reactive logic is reused and how many reactive dependencies are tracked, impacting interaction responsiveness and memory usage.
import { ref } from 'vue'; const sharedCount = ref(0); export function useSharedCounter() { function increment() { sharedCount.value++; } return { count: sharedCount, increment }; } // Components share the same reactive state
import { ref } from 'vue'; export function useCounter() { const count = ref(0); function increment() { count.value++; } return { count, increment }; } // Used inside multiple components without memoization or shared state
| Pattern | Reactive Dependencies | Memory Usage | Update Cost | Verdict |
|---|---|---|---|---|
| Separate reactive state per component | High (one per instance) | High | High (many updates) | [X] Bad |
| Shared reactive state in composable | Low (shared once) | Low | Low (single source) | [OK] Good |