# Example: Component Creation and Re-Initialization
```
@Entry
@Component
struct ParentComp {
@State isCountDown: boolean = true
build() {
Column() {
Text(this.isCountDown ? 'Count Down' : 'Stopwatch')
if (this.isCountDown) {
Image('countdown.png')
TimerComponent({counter: 10, changePerSec: -1, showInColor: Color.Red})
} else {
Image('stopwatch.png')
TimerComponent({counter: 0, changePerSec: +1, showInColor: Color.Black })
}
Button(this.isCountDown ? 'Swtich to Stopwatch' : 'Switch to Count Down')
.onClick(() => {this.isCountDown = !this.isCountDown})
}
}
}
// Manage and display a count down / stop watch timer
@Component
struct TimerComponent {
@State counter: number = 0
private changePerSec: number = -1
private showInColor: Color = Color.Black
private timerId : number = -1
build() {
Text(`${this.counter}sec`)
.fontColor(this.showInColor)
}
aboutToAppear() {
this.timerId = setInterval(() => {this.counter += this.changePerSec}, 1000)
}
aboutToDisappear() {
if (this.timerId > 0) {
clearTimeout(this.timerId)
this.timerId = -1
}
}
}
```
## Initial Creation and Rendering
1. Create the parent component **ParentComp**.
2. Locally initialize the state variable **isCountDown** of **ParentComp**.
3. Execute the **build** function of **ParentComp**.
4. Create a preset **** component.
1. Create a preset **** component, set the text content to be displayed, and add the **** component instance to the **** component.
2. The component on the **true** branch is created based on the **if** condition.
1. Create a preset **** component and set the image source address.
2. Creates a **TimerComponent** using the given constructor.
1. Create a **TimerComponent** object.
2. Initialize the values of member variables locally.
3. Use the parameters provided by the **TimerComponent** constructor to update the values of member variables.
4. Execute the **aboutToAppear** function of **TimerComponent**.
5. Execute the **build** function of **TimerComponent** to create the corresponding UI description structure.
3. Create a preset **