WebComp provides the exact same lifecycle methods as React:
When is it called?
Before the component gets mounted to the DOM
After the component gets mounted to the DOM
Before component is removed from the DOM
Before new props are accepted
Right before render(), both on the initial mount and on subsequent updates
Before render() is called. Return `false` to prevent render
Before the most recently rendered output is committed to the DOM. Any value returned by this lifecycle will be passed as a parameter to
Note: Lifecycle methods don't work in stateless components and string render.
In addition to component lifecycle, WebComp also provides lifecycle methods for custom element itself.
Keep in mind that these are for the elements themselves, not underlying Preact component instances, so all these methods are
When Is It Called?
Immediately after custom element was initialized in the scope of the page
When an element is about to get added to the DOM
Once an element has been connected to the DOM (content may not be rendered yet)
Before component is disconnected from the DOM
Once component has been disconnected from the DOM
Element's contents were rendered