DEV Community

Discussion on: Angular: Is trackBy necessary with ngFor?

Collapse
 
fyodorio profile image
Fyodor

That actually makes total sense and one shouldn't just use trackBy religiously (as any other recommended "best practice"), but rather consider each iterable use case separately.

There are use cases though where absence of trackBy can cause huge performance drops. For instance when one iterates over component instances that have some costly calculations inside (triggered in ngOnInit, for instance). If these calculations don't need to be triggered if nothing changes for a specific item, trackBy will save a ton of potentially lost milliseconds.

So salt is the key, as always - you should always take everything with a grain of it.