I am looking to enhance my understanding of how ChangeDetection works, and I have a query in this regard.
When using
changeDetection: ChangeDetectionStrategy.OnPush
, do I also need to check if currentValue
exists in the ngOnChanges
lifecycle hook, or is it sufficient to just verify if the input has changed?
Allow me to provide an example to clarify my question:
As previously mentioned, with
changeDetection: ChangeDetectionStrategy.OnPush
, I have an input like this: @Input() isInspectionReopened: boolean;
. My ngOnChanges
function looks as follows:
ngOnChanges(changes: SimpleChanges) {
if(changes.isInspectionReopened) {
// do something
}
}
Should I only check changes.isInspectionReopened
, or do I also need to consider adding
changes.isInspectionReopened.currentValue
?