SfSkills Domains Docs GitHub

Home / lwc / lwc-state-management

lwc-state-management

Share state across LWCs using pub/sub, Lightning Message Service, @wire, and reactive stores. NOT for in-component reactivity — use lwc/lwc-reactive-state-patterns.

Open the skill folder on GitHub


LWC State Management

LWC has four state-sharing mechanisms: (1) parent→child via public @api properties, (2) @wire for server-synced data, (3) Lightning Message Service for sibling LWCs/Aura, (4) custom events for child→parent. This skill picks the right mechanism based on component distance and persistence requirements, and shows why legacy pubsub and heavy external stores (Redux, MobX) should be avoided in favor of these native primitives plus tiny singleton signals.

Adoption Signals

Any time two non-parent/child LWCs must stay in sync. Not for tiny local state.

  1. Parent→child: public @api props + custom events.
  2. Sibling LWCs: Lightning Message Service via a message channel (@salesforce/messageChannel/Foo__c).
  3. Server data: @wire — it's reactive and cached.
  4. App-wide reactive store: a singleton module exporting a signal-like observable; use sparingly.
  5. Platform state managers (Summer '26 GA): For cross-component reactive state without hand-rolled singletons, use defineState() from @lwc/state (atom, computed, setAtom in the setup callback) or the built-in lightning/stateManager* modules (record, objectInfo, layout, related lists). Not available in Experience Cloud at Summer '26 — fall back to LMS or getters there.
  6. For Aura↔LWC interop use LMS; pubsub library is legacy.

Key Considerations

Worked Examples (see references/examples.md)

Common Gotchas (see references/gotchas.md)

Top LLM Anti-Patterns (full list in references/llm-anti-patterns.md)

Official Sources Used

Package files