hmos-arkui-statemgt-migration

Migrate ArkUI state management code from V1 decorators to V2 equivalents.

2|Updated Jun 21, 2026
One-click install
npx skills add https://github.com/IsKenKenYa/skills --skill hmos-arkui-statemgt-migration-iskenkenya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hmos-arkui-statemgt-migration
Source: https://github.com/IsKenKenYa/skills/tree/main/skills/harmonyos/development/application-framework/ArkUI/hmos-arkui-statemgt-migration
Command: npx skills add https://github.com/IsKenKenYa/skills --skill hmos-arkui-statemgt-migration-iskenkenya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? HarmonyOS developers upgrading ArkUI applications face a complex, error-prone migration from state management V1 to V2, involving dozens of decorator renames, changed observation semantics, and new APIs like Repeat, AppStorageV2, and PersistenceV2. ## Core Features & Use Cases - Complete Decorator Mapping: Converts @Component/@State/@Prop/@Link/@Observed/@ObjectLink/@Provide/@Consume/@Watch/@Reusable to their V2 counterparts (@ComponentV2/@Local/@Param/@Event/@ObservedV2/@Trace/@Provider/@Consumer/@Monitor/@ReusableV2). - Application-Level State Migration: Migrates LocalStorage, AppStorage, PersistentStorage, and Environment to @ObservedV2 singletons, AppStorageV2, PersistenceV2, and UIAbilityContext.config. - Rendering & Special Cases: Converts ForEach/LazyForEach to Repeat with virtualScroll, handles animateTo compatibility via UIUtils.applySync, and wraps built-in objects like ChildrenMainSize with UIUtils.makeObserved. - Use Case: Given a V1 project using @StorageLink and LazyForEach, the skill scans the decorators, produces a migration checklist, and rewrites the code to AppStorageV2.connect() and Repeat with .virtualScroll(). ## Quick Start Ask the assistant to migrate your ArkUI page using @State, @Link, and LazyForEach from state management V1 to V2.

Frequently Asked Questions about hmos-arkui-statemgt-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate ArkUI @State and @Link decorators to V2?

Replace @State with @Local for internal state, or @Param @Once when external initialization is needed. Replace @Link with @Param plus an @Event callback, since V2 has no built-in two-way synchronization between parent and child components.

How to migrate ForEach and LazyForEach to Repeat in ArkUI V2?

Convert ForEach to Repeat with .each() and .key(), and convert LazyForEach to Repeat with .virtualScroll() for lazy loading. V2 lets you modify arrays directly with push or splice instead of implementing IDataSource and calling notifyDataChange.

What replaces AppStorage and LocalStorage in ArkUI state management V2?

AppStorage is replaced by AppStorageV2.connect() with an @ObservedV2 class using @Trace properties. LocalStorage is replaced by an @ObservedV2 singleton class, and PersistentStorage becomes PersistenceV2 with globalConnect.

Why does animateTo not apply earlier state changes in ArkUI V2?

In V2, state modifications before animateTo may not take effect because updates are batched. Wrap the pre-animation state changes in UIUtils.applySync() (API 22+) or use animateToImmediately with zero duration on earlier versions.

Does ArkUI V2 support deep observation of nested object properties?

Yes, V2 supports deep observation through @ObservedV2 on the class and @Trace on each property, replacing the V1 pattern of @Observed plus @ObjectLink subcomponents. Each nesting level needs its own @ObservedV2 and @Trace annotations.

What API version is required for ArkUI state management V2 migration?

The migration requires API version 12 or higher; projects below API 12 must upgrade first. Some fixes like UIUtils.applySync for animateTo require API version 22 or later.