1e41f4b71Sopenharmony_ci# \@ComponentV2 Decorator: Custom Component
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciTo use the capability of the state variable decorator V2 in a custom component, you can use the \@ComponentV2 Decorator to decorate the custom component.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>**NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>The \@ComponentV2 decorator is supported since API version 12.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>State management V2 is still under development, and some features may be incomplete or not always work as expected.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## Overview
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciSimilar to [\@Component Decorator](arkts-create-custom-components.md), the \@ComponentV2 decorator is used to decorate custom components.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci- In the custom component decorated by \@ComponentV2, only new state variable decorators can be used, including \@Local, \@Param, \@Once, \@Event, \@Provider, and \@Consumer.
17e41f4b71Sopenharmony_ci- Custom components decorated by \@ComponentV2 do not support component reuse and LocalStorage.
18e41f4b71Sopenharmony_ci- \@ComponentV2 and \@Component cannot be used to decorate the same struct.
19e41f4b71Sopenharmony_ci- \@ComponentV2 can use an optional parameter **freezeWhenInactive** of the **boolean** type to implement the [component freezing](arkts-custom-components-freezeV2.md).
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci- A simple \@ComponentV2 decorated custom component should contain the following parts:
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci    ```ts
24e41f4b71Sopenharmony_ci    @ComponentV2 // Decorator
25e41f4b71Sopenharmony_ci    struct Index { // Data declared by the struct
26e41f4b71Sopenharmony_ci      build() { // UI defined by build
27e41f4b71Sopenharmony_ci      }
28e41f4b71Sopenharmony_ci    }
29e41f4b71Sopenharmony_ci    ```
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciUnless otherwise specified, a custom component decorated by \@ComponentV2 maintains the same behavior as a custom component decorated by \@Component.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## Constraints
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ciWhen a custom component decorated by \@Component is used together with a custom component decorated by \@ComponentV2, variable is not allowed to pass in the following cases:
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci- Normal variables (which are not decorated or updated) in a custom component decorated by \@ComponentV2 are constructed and assigned values by the parent component decorated by \@Component or \@CompoentV2.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci- Pass object variables (except string, number, boolean, enum, null, and undefined) decorated by \@State, \@Prop, \@Link, \@ObjectLink, \@Provide, \@Consume, \@StorageLink, \@StorageProp, \@LocalStorageLink, or \@LocalStorageProp to the variables decorated by \@Param or \@Event in a custom component decorated by \@ComponentV2.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci- Pass the variables decorated by \@Local, \@Param, \@Event, \@Provider, or \@Consumer of the Set, Map, Date, or Array types to the variables decorated by \@State, \@Prop, \@ObjectLink, and \@Provide in a custom component decorated by \@Component.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci- The variable decorated by \@Link in the custom component decorated by \@Component is constructed and assigned values by the parent component decorated by \@ComponentV2.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci- The variable decorated by \@State, \@Prop, \@Link, \@Provide, \@Consume, \@StorageLink, \@StorageProp, \@LocalStorageLink, or \@LocalStorageProp in a custom component decorated by \@Component, and the type of the variable is a \@ObservedV2 decorated class.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci- The variable decorated by \@Param, \@Local, \@Event, \@Provider(), and \@Consumer() in a custom component decorated by \@ComponentV2 and the type of the variable is a \@Observed decorated class.
48