1e41f4b71Sopenharmony_ci# Show/Hide Event
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe show/hide event is triggered when a component is mounted or unmounted from the component tree. A component appears when mounted to the component tree and disappears when unmounted from the component tree.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## onAttach<sup>12+</sup>
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_cionAttach(callback: Callback\<void>): T
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciCalled when this component is mounted to the component tree.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci> **NOTE**
16e41f4b71Sopenharmony_ci>
17e41f4b71Sopenharmony_ci> The callback must be called before the component layout and rendering process.
18e41f4b71Sopenharmony_ci>
19e41f4b71Sopenharmony_ci> It is not allowed to make changes to the component tree in the callback, for example, initiating animations or altering the component tree structure with **if-else** statements.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Return value**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Type| Description|
28e41f4b71Sopenharmony_ci| -------- | -------- |
29e41f4b71Sopenharmony_ci| T | Current component.|
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci## onDetach<sup>12+</sup>
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_cionDetach(callback: Callback\<void>): T
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciCalled when this component is unmounted from the component tree.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**Return value**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| Type| Description|
45e41f4b71Sopenharmony_ci| -------- | -------- |
46e41f4b71Sopenharmony_ci| T | Current component.|
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci## onAppear
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_cionAppear(event: () => void): T
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ciCalled when this component is displayed.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci> **NOTE**
55e41f4b71Sopenharmony_ci>
56e41f4b71Sopenharmony_ci> This callback may be called after the component layout and rendering process.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Return value**
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci| Type| Description|
67e41f4b71Sopenharmony_ci| -------- | -------- |
68e41f4b71Sopenharmony_ci| T | Current component.|
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci## onDisAppear
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_cionDisAppear(event: () => void): T
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ciTriggered when the component is hidden.
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Return value**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci| Type| Description|
86e41f4b71Sopenharmony_ci| -------- | -------- |
87e41f4b71Sopenharmony_ci| T | Current component.|
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci## Example
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```ts
93e41f4b71Sopenharmony_ci// xxx.ets
94e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI'
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci@Entry
97e41f4b71Sopenharmony_ci@Component
98e41f4b71Sopenharmony_cistruct AppearExample {
99e41f4b71Sopenharmony_ci  @State isShow: boolean = true
100e41f4b71Sopenharmony_ci  @State changeAppear: string = 'Show/Hide'
101e41f4b71Sopenharmony_ci  private myText: string = 'Text for onAppear'
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci  build() {
104e41f4b71Sopenharmony_ci    Column() {
105e41f4b71Sopenharmony_ci      Button(this.changeAppear)
106e41f4b71Sopenharmony_ci        .onClick(() => {
107e41f4b71Sopenharmony_ci          this.isShow = !this.isShow
108e41f4b71Sopenharmony_ci        }).margin(15)
109e41f4b71Sopenharmony_ci      if (this.isShow) {
110e41f4b71Sopenharmony_ci        Text(this.myText).fontSize(26).fontWeight(FontWeight.Bold)
111e41f4b71Sopenharmony_ci          .onAttach(() => {
112e41f4b71Sopenharmony_ci            promptAction.showToast({
113e41f4b71Sopenharmony_ci              message: 'Text shown.',
114e41f4b71Sopenharmony_ci              duration: 2000,
115e41f4b71Sopenharmony_ci              bottom: 500
116e41f4b71Sopenharmony_ci            })
117e41f4b71Sopenharmony_ci          })
118e41f4b71Sopenharmony_ci          .onDetach(() => {
119e41f4b71Sopenharmony_ci            promptAction.showToast({
120e41f4b71Sopenharmony_ci              message: 'Text hidden.',
121e41f4b71Sopenharmony_ci              duration: 2000,
122e41f4b71Sopenharmony_ci              bottom: 500
123e41f4b71Sopenharmony_ci            })
124e41f4b71Sopenharmony_ci          })
125e41f4b71Sopenharmony_ci      }
126e41f4b71Sopenharmony_ci    }.padding(30).width('100%')
127e41f4b71Sopenharmony_ci  }
128e41f4b71Sopenharmony_ci}
129e41f4b71Sopenharmony_ci```
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci![en-us_image_0000001219864151](figures/en-us_image_0000001219864151.gif)
132