>This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version.
> **NOTE**
>
> This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version.
We provide a range of lifecycle callbacks for custom components, including **onInit**, **onAttached**, **onDetached**, **onLayoutReady**, **onDestroy**, **onPageShow**, and **onPageHide**. You can use these callbacks to manage the internal logic of your custom components. The following describes the times when the lifecycle callbacks are invoked.
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="p1395313418212"><aname="p1395313418212"></a><aname="p1395313418212"></a>Triggered once, when a custom component is created.</p>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="a2e00e7dee8164661b4244c4a34ae9b2c"><aname="a2e00e7dee8164661b4244c4a34ae9b2c"></a><aname="a2e00e7dee8164661b4244c4a34ae9b2c"></a>Triggered when a custom component is added to the <strongid="b22203210291"><aname="b22203210291"></a><aname="b22203210291"></a><Page></strong> component tree. When this callback is triggered, related data can be displayed during the lifecycle in scenarios such as image loading and animation playback.</p>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="a23c4cbd18ad24bd8a496dbc487dd5400"><aname="a23c4cbd18ad24bd8a496dbc487dd5400"></a><aname="a23c4cbd18ad24bd8a496dbc487dd5400"></a>Triggered when layout calculation, including content size and position adjustment, is complete for a custom component.</p>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="ae54d3a1f653c495ba8950e82c0fb3db4"><aname="ae54d3a1f653c495ba8950e82c0fb3db4"></a><aname="ae54d3a1f653c495ba8950e82c0fb3db4"></a>Triggered when a custom component is removed. It is usually used to stop animation or asynchronous logic execution.</p>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="aab6fb684fd454b41a6f701628f9c2307"><aname="aab6fb684fd454b41a6f701628f9c2307"></a><aname="aab6fb684fd454b41a6f701628f9c2307"></a>Triggered when a custom component is destroyed. It is usually used to release resources.</p>
<tdclass="cellrowborder"valign="top"width="18.751875187518753%"headers="mcps1.1.5.1.3 "><pid="p3315111550"><aname="p3315111550"></a><aname="p3315111550"></a>Page display of a custom component</p>
</td>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="p831518111558"><aname="p831518111558"></a><aname="p831518111558"></a>Triggered when the page where a custom component is located is displayed.</p>
<tdclass="cellrowborder"valign="top"width="18.751875187518753%"headers="mcps1.1.5.1.3 "><pid="p434816271172"><aname="p434816271172"></a><aname="p434816271172"></a>Page hiding of a custom component</p>
</td>
<tdclass="cellrowborder"valign="top"width="56.685668566856684%"headers="mcps1.1.5.1.4 "><pid="p73481627873"><aname="p73481627873"></a><aname="p73481627873"></a>Triggered when the page where a custom component is located is hidden.</p>
</td>
</tr>
</tbody>
</table>
We provide a range of lifecycle callbacks for custom components, including **onInit**, **onAttached**, **onDetached**, **onLayoutReady**, **onDestroy**, **onShow**, and **onHide**. You can use these callbacks to manage the internal logic of your custom components. The following describes the times when the lifecycle callbacks are invoked.
| onInit | Function | Custom component initialization | The custom component is created. This callback is invoked once.|
| onAttached | Function | Custom component loading | The custom component is added to the **\<Page>** component tree. When this callback is invoked, related data can be displayed during the lifecycle in scenarios such as image loading and animation playback.|
| onLayoutReady | Function | Component layout completion| Layout calculation, including content size and position adjustment, is complete for the custom component.|
| onDetached | Function | Custom component removal | The custom component is removed. It is usually used to stop animation or asynchronous logic execution.|
| onDestroy | Function | Custom component destruction | The custom component is destroyed. It is usually used to release resources. |
| onShow | Function | Page display of a custom component| The page where the custom component is located is displayed. |
| onHide | Function | Page hiding of a custom component| The page where the custom component is located is hidden. |