stage0
stage0 copied to clipboard
Lifecycle events - Any destroy/unmount/componentWillUmmount equivalent event?
Often times we need to perform some cleanup before a node is removed from DOM, such as clearing timeouts, etc.
Are there any such callbacks/events that will be called prior to unmounting?
Skimming through reconcile(), I don't see anywhere the presence of such logic before .removeChild() is called.
Yep, reconcile doesn't have unmount callback, and was designed without any lifecycle managing in mind.
The problems that I see with implementing unmount cb:
- It will affect performance on clearing and removing nodes.
- For lifecycles to work properly, all system need some way to propagate these events throughout the tree up and down, so you don't need to carry unmount housekeeping on each reconcile call level. Like if you have rendered list of components that have array inside each/some of them. This is the point where Virtual DOM systems fits really nice.
I have some ideas on how to redesign API to fit such cases better. Will keep this issue open and update once will be implemented.