State Management Examples
During the beta of LWC state management, documentation is limited. But the best documentation for code-based features is examples of those features in use.
State management has a dedicated repository on GitHub with several example implementations. You can find the repo under the forcedotcom org:
https://github.com/forcedotcom/state-management
The repo currently contains two examples.
This simple example provides a minimal implementation of a state manager. It demonstrates how to define a state manager, how to use it to retrieve Salesforce metadata and data, and how to show state manager data in your LWC user interface.
This example also demonstrates how to compose nested state managers, by using the lightning/stateManagerRecord and lightning/stateManagerLayout state managers. These built-in state managers wrap related UI API calls, providing an alternative to calling them directly, or via @wire.
This example is more complex. It provides a set of related components that demonstrate using a state manager to maintain the state of a shopping cart in a simple online store.
Rather than retrieving data from Salesforce, it shows how to build and manipulate local data that isn't ready to be sent to a server yet, but still needs coherent logic to ensure that correct, always current information is used or shown.