Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security NachrichtenFoto-News: Nikons Vollformatkamera ohne Sucher, neues Luminar(24.09.2026 um 16:21 Uhr)
IT Security NachrichtenIs your Apple Watch 12 or Ultra 4 randomly restarting? Here’s the fix(24.09.2026 um 15:42 Uhr)
IT Security DownloadsGitHub Release: nextcloud/server v35.0.1 (24.09.2026)(24.09.2026 um 15:54 Uhr)
IT Security DownloadsBlueStacks Download - Android-Apps auf dem PC nutzen(24.09.2026 um 15:18 Uhr)
IT NachrichtenFive years later, you can finally buy Google Beam(24.09.2026 um 15:26 Uhr)
IT Security NachrichtenFoto-News: Nikons Vollformatkamera ohne Sucher, neues Luminar(24.09.2026 um 16:21 Uhr)
IT Security NachrichtenIs your Apple Watch 12 or Ultra 4 randomly restarting? Here’s the fix(24.09.2026 um 15:42 Uhr)
IT Security DownloadsGitHub Release: nextcloud/server v35.0.1 (24.09.2026)(24.09.2026 um 15:54 Uhr)
IT Security DownloadsBlueStacks Download - Android-Apps auf dem PC nutzen(24.09.2026 um 15:18 Uhr)
IT NachrichtenFive years later, you can finally buy Google Beam(24.09.2026 um 15:26 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Understanding LocalStorage, AppStorage, and AppStorageV2 in ArkTS: What’s the Difference?

Read the original article:Understanding LocalStorage, AppStorage, and AppStorageV2 in ArkTS: What’s the Difference? If you’ve been diving into HarmonyOS development with ArkTS, you’ve probably come across decorators like @LocalStorage, @Ap…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Read the original article:Understanding LocalStorage, AppStorage, and AppStorageV2 in ArkTS: What’s the Difference?



If you’ve been diving into HarmonyOS development with ArkTS, you’ve probably come across decorators like @LocalStorage, @AppStorage, or maybe even the newer @AppStorageV2. At first glance, they all seem to do similar things—helping you store and share state. But dig a little deeper and you'll find they serve very different purposes.



Let’s break them down and see how they differ, when to use which, and what you need to watch out for.






📌 Introduction



State management is a big deal in reactive UI frameworks. Whether you’re building a fitness tracker, an e-commerce app, or a simple counter, how you store and share data across your components matters — for performance, maintainability, and user experience.



ArkTS offers three built-in decorators to help with state:




  • @LocalStorage: Local, non-persistent state

  • @AppStorage: Global and persistent

  • @AppStorageV2: Global, persistent, and smarter (with field-level tracking)






🔍 Let’s Break Them Down



@LocalStorage: Your Local Helper

Use @LocalStorage when you need a variable that lives only inside a component. It won’t persist when the app restarts, and you can’t access it from another page. But it’s super lightweight.




import { LocalStorage } from '@ohos.state';

@LocalStorage('counter', 0)
let counter: number;

Text(`${counter}`); // automatically updates when counter changes






@AppStorage: The Global Key-Value Store

Need a variable that multiple components can read/write to, and that sticks around even after the app closes? @AppStorage is your friend.




import { AppStorage } from '@ohos.state';

@AppStorage('theme')
let theme: string = 'light';

Text(`${theme}`);






It’s like having a global config that the entire app can observe. Change it in one place, and it updates everywhere. Easy, right?



But here’s the catch: it only works well with primitive types like strings, numbers, and booleans. Complex objects? Not so much.



@AppStorageV2: The New Kid With Superpowers

If @AppStorage is good, @AppStorageV2 is better, especially if you're working with structured data. It supports classes, field-level tracking (thanks to @trace), and it plays nice with ArkTS's compiler for better performance and memory usage.




import { AppStorageV2, Trace } from '@ohos.state';

@AppStorageV2
class Settings {
@Trace theme: string = 'light';
@Trace volume: number = 50;
}

let settings = Settings.getSharedInstance();
Text(`${settings.theme}`);






With @trace, only the exact fields that change trigger updates—no unnecessary re-renders, no wasted CPU cycles.






🧪 Quick Comparison Table



Press enter or click to view image in full size








🤔 So When Should You Use What



Use @LocalStorage when:




  • You need temporary state inside a single component.

  • You don’t care about persistence or cross-component syncing.



Use @AppStorage when:




  • You need a simple global state, like a language or theme toggle.

  • You’re only working with primitive values.



Use @AppStorageV2 when:




  • You need to manage complex global state across pages.

  • You care about performance and clean code.

  • You want to track specific fields and avoid unnecessary UI updates.






⚠️ Limitations and Things to Watch Out For




  • @LocalStorage doesn’t persist—so don’t use it for user settings or anything critical.

  • @AppStorage can feel limited when your app grows and you need more structure.

  • @AppStorageV2 is powerful, but it requires more setup—you’ll need to define classes and annotate fields.






👋 Conclusion



These decorators may look similar, but they serve different jobs. Think of them as tools in your state management toolbox. If you’re just getting started, @AppStorage might be all you need. But for apps that scale—or need performance—@AppStorageV2 is where you should be heading.



HarmonyOS is evolving fast, and with it, the way we manage state in ArkTS. Understanding these decorators early on will help you write more efficient, modular, and scalable apps.



Have you tried @AppStorageV2 in a real project? Found any gotchas or tips? Drop them in the comments—we’re all learning here.






References



LocalStorage: Storing UI State



AppStorage: Storing Application-wide UI State



AppStorageV2: Storing Application-wide UI State



https://forums.developer.huawei.com/forumPortal/en/topic/0201190275244638088



Written by Zulfu

SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Understanding LocalStorage, AppStorage, and AppStorageV2 in ArkTS: What’s the Difference?
id: e4d2fdae-a1d7-4ff1-81b1-1a1886d2a159
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Understanding LocalStorage, Ap" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Understanding LocalStorage, AppStorage, .... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Understanding LocalStorage, AppStorage, and AppStorageV2 in ArkTS: What’s the Difference?

Thematisch verwandte Begriffe: Understanding, LocalStorage, AppStorage, AppStorageV2 · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97179 | A security vulnerability has been detected in O2OA up to 9.5.3/10.0.2. T…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick