Performance: Composable with lifecycle hooks
MEDIUM IMPACT
This affects how efficiently Vue components manage side effects and resource cleanup during rendering and interaction.
import { onMounted, onUnmounted } from 'vue'; export function useTimer() { let intervalId = null; onMounted(() => { intervalId = setInterval(() => { console.log('tick'); }, 1000); }); onUnmounted(() => { clearInterval(intervalId); }); }
import { onMounted, onUnmounted } from 'vue'; export function useTimer() { let intervalId = null; onMounted(() => { intervalId = setInterval(() => { console.log('tick'); }, 1000); }); // Missing cleanup on unmount }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Composable without cleanup | Minimal | 0 | Low but ongoing CPU usage | [X] Bad |
| Composable with proper lifecycle cleanup | Minimal | 0 | Low and stops when unused | [OK] Good |