Welcome to the Treehouse Community
Looking to learn something new?
Richard Nash24,862 Points
What is a "lifecycle callback"? In fact, what is a "callback"?
I've seen this term thrown around a bunch and i'm still a little hazy on it, but what is a "callback"? Why does it exist and what does it do? Why should I care? etc...
And on top of that I've heard the term "lifecycle callback" which I also don't understand because of my lack of understanding of the first question.
So any light that can be shed on this topic would be most appreciated.
Thank you :-)
Steven Parker216,149 Points
A "callback" is essentially a function passed as an argument to another function.
The callback function will be invoked at some later time as a result of some event occurring or process completing. For example:
In this call to setTimeout, the argument elapsed is the name of a callback function that will be called 1 second (1000 milliseconds) later.
A lifecycle callback would be a similar function that would get called multiple times during the life of an associated entity, unlike the example just given where elapsed would be called only once. It would likely be called to indicate changes in the state of the entity, or to indicate milestones in a concurrent process.