# ArkTS Syntax Usage ## How do I dynamically create components using code in ArkUI? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Solution** ArkUI uses the ArkTS declarative development paradigm. Developers cannot hold component instances. During declaration, you can control component creation by rendering control syntax and dynamically building UI elements. **Example** ``` // Create a component using the if statement. if(this.isTrue) { Text ("Create Text Component").fontSize (30) } // Create a component using the ForEach statement. ForEach(this.nums,(item) => { Text(item + '').fontSize(30) },item => JSON.stringify(item)) ``` **Reference** [Overview of Rendering Control](../quick-start/arkts-rendering-control-overview.md) ## What is the difference between an @Builder decorated method and a regular method? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Solution** The @Builder decorated method allows for use of a custom component, while regular methods do not. If a custom component is used in an @Builder decorated method, it is re-created each time the method is called. **Reference** [@BuilderParam](../quick-start/arkts-builderparam.md) ## How do I define @BuilderParam decorated attributes? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Solution** - Without parameters If no parameter is passed when assigning a value to the **@BuilderParam** decorated attribute (for example, **content: this.specificParam**), define the type of the attribute as a function without a return value (for example, **@BuilderParam content: \(\) =\> void**). - With parameters If any parameter is passed when assigning a value to the **@BuilderParam** decorated attribute (for example, **callContent: this.specificParam1\("111"\)**), define the type of the attribute as **any** (for example, **@BuilderParam callContent: any**). **Reference** [@BuilderParam](../quick-start/arkts-builderparam.md) ## How do I listen for object changes in an array? Applicable to: OpenHarmony 3.2 Beta5 (API version 9) **Solution** To listen for object changes in an array, use the @Observed and @ObjectLink decorators. **@Observed** applies to classes, and **@ObjectLink** applies to variables. **Example** 1. Use @Observed on a class. ``` @Observed class ClassA { public name: string public c: number public id: number constructor(c: number, name: string = 'OK') { this.name = name this.c = c } } ``` 2. Use @ObjectLink on a component variable. ``` @Component struct ViewA { label: string = 'ViewA1' @ObjectLink a: ClassA build() { Row() { Button(`ViewA [${this.label}] this.a.c= ${this.a.c} +1`) .onClick(() => { this.a.c += 1 }) }.margin({ top: 10 }) } } ``` **Reference** [\@Observed and \@ObjectLink: Observing Attribute Changes in Nested Class Objects](../quick-start/arkts-observed-and-objectlink.md) ## How do I transfer values through the parent component to @Link decorated varaibles in a child component? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Solution** To enable a child component to receive the value from the parent component through @Link, '**\$**' must be used to first establish a reference relationship between variables in the child and parent components. **Example** The **@Link** semantics are derived from the '**$**' operator. In other words, **\$isPlaying** is the two-way binding of the internal state **this.isPlaying**. When the button in the **PlayButton** child component is touched, the value of the @Link decorated variable is changed, and **PlayButton** together with the **\** and **\** components of the parent component is refreshed. Similarly, when the button in the parent component is touched, the value of **this.isPlaying** is changed, and **PlayButton** together with the **\** and **\