Data Guidelines
Lightning Data Service
State Management Compared with Alternatives
Share a State Manager Across Components
Nested State Managers
State Management Examples
Call APIs from Apex
Work with Errors
Develop Secure Code
There are a few ways to share common data across components in an LWC app. For example, you can set properties on child components to pass data into them from the parent. Events let you send data in the opposite direction. These simple solutions can be optimal for many apps, or a small set of related components that work together.
State management can work well in those situations too. However, it’s specifically designed to optimize data sharing for an app or collection of components that’s grown large and complex. For example, you don’t want to pass property values down chains of a dozen or more child components, or send events back up the same long hierarchy. A state manager is a “black box” that holds a set of related data values that are managed in a consistent way. Components in a shared subtree can access a state manager instance through the component hierarchy. You can also export a singleton state manager from a shared module, which gives all components that import it access to the same instance. Then, a component can use the state manager to read values managed elsewhere, or to perform safe, managed changes to the contents.
Developers can use LWC state management to address various challenges that arise from size and complexity.
@wire in many places.LWC state management aims to provide an idiomatic way to manage state for larger collections of components (apps), making it more obvious how to retrieve, transform, distribute, and present data.