#72 Default values in didReceiveAttrs

Component in ember have a hook called didReceiveAttrs, it runs after init, and it also runs on subsequent re-renders, which is useful for logic that is the same on all renders.
According to ember’s documentation:
Since the didReceiveAttrs hook is called every time a component’s attributes are updated whether on render or re-render, you can use the hook to effectively act as an observer, ensuring code is executed every time an attribute changes.So you could use this hook for setting default values on component attributes, for example:

The above code will set direction to ‘down’ and age to the default value of 18.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu