Getting into it
You know that moment when a list in Angular looks fine, but the app starts feeling weirdly slow when you add one item or sort the list. I see it a lot with *ngFor. You change the data, and suddenly Angular acts like it has to rebuild the whole list from scratch. The screen flickers a bit, inputs lose focus, and it just feels messy.
That’s where trackBy comes in. It gives Angular a clear way to tell which item is which, so it can keep the DOM nodes that already exist and only update what actually changed. Instead of tearing everything down and putting it back, it keeps its hands off most of the list. When you’re rendering lots of items, or updating them often, this can be the difference between “works” and “works smooth”.
Quick ending
If your lists are jumping around or reloading too much during updates, using trackBy with *ngFor is one of those small fixes that hits hard. Less DOM work, fewer annoying UI glitches.