Performance: @Input decorator for parent to child
MEDIUM IMPACT
This affects how data is passed and rendered between parent and child components, impacting rendering speed and interaction responsiveness.
Parent template: <child-comp [data]="parentData" *ngIf="shouldShowChild"></child-comp> Child component: @Input() data: any; // Parent updates data only when necessary, uses OnPush change detection
Parent template: <child-comp [data]="parentData"></child-comp> Child component: @Input() data: any; // Parent updates parentData frequently even if child doesn't need it
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent input updates without OnPush | Many DOM updates | Multiple reflows | High paint cost | [X] Bad |
| Input updates with OnPush and immutable data | Minimal DOM updates | Single reflow | Low paint cost | [OK] Good |