Component lifecycle hook arguments are being deprecated

by Ryan Toronto

Component lifecycle hooks currently receive a list of previous and current attributes as arguments:


  didReceiveAttrs({ oldAttrs, newAttrs }) {
    console.log('old attributes', oldAttrs);
    console.log('new attributes', newAttrs);


These arguments are being deprecated, mainly due to the performance cost of keeping track of old attributes for every component, even if those attributes were never used.

How will this affect you? One reason you might be currently using these arguments is to notify a component when a specific value changes. In this way, the arguments solved a similar problem that observers originally did. You could compare the old and new attribute value, and run some code if the values were different.

Even with the deprecation, this pattern is still viable, but you'll now need to track the old attribute values yourself. There is example code in the RFC that outlines how you might do this.

If your application has several components that rely heavily on tracking old attribute values, expect there to be a number addons addressing this issue to appear in the coming months. Even though old attribute tracking is being removed from Ember core, there's still a need for the functionality, and addons are the perfect place for exploring what a good shared solution might look like.


Send us a tweet:

Or ask us in Inside EmberMap, our private Slack workspace for subscribers.