Performance: Directive hooks (mounted, updated, unmounted)
MEDIUM IMPACT
Directive hooks affect how and when DOM updates happen, impacting rendering speed and responsiveness.
mounted(el) { el.style.color = 'red'; } updated(el, binding) { if (binding.oldValue !== binding.value) { el.style.color = binding.value; } }mounted(el) { el.style.color = 'red'; } updated(el) { el.style.color = 'red'; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unconditional style update in updated hook | Multiple writes per update | Triggers reflow every update | High paint cost | [X] Bad |
| Conditional style update checking value change | Writes only on change | Reflow only when needed | Lower paint cost | [OK] Good |