Lifecycle Methods

Component lifecycle methods

Sandstone components provide exact same lifecycle methods as React:

Method Name When is it called?
componentWillMount Before the component gets mounted to the DOM
componentDidMount After the component gets mounted to the DOM
componentWillUnmount Before component is removed from the DOM
componentWillReceiveProps Before new props are accepted
shouldComponentUpdate Before render() is called. Return false to prevent render
componentWillUpdate Before render()
componentDidUpdate After render()

React's newly announced getDerivedStateFromProps and getSnapshotBeforeUpdate will be supported once Preact adds support for them.

Note: Lifecycle methods don't work in stateless components and string render.

Element lifecycle methods

In addition to component lifecycle, Sandstone 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 static.

Method Name When is it called?
elementDidCreate Immediately after custom element was created
elementWillConnect When an element is about to get rendered to the DOM
elementDidConnect Once an element has been connected to the DOM (content may not be rendered yet)
elementWillDisconnect Before component is disconnected from the DOM
elementDidDisconnect Once component has been disconnected from the DOM
elementDidRender Element's contents were rendered

Next: Render from string →

results matching ""

    No results matching ""