State

Component state is stored in the DOM, and bindings are established in mounted components. State references necessitate the definition of an interface model via the static define.state object within components, supporting various definition structures.

Type Constructors

In the following code snippet, we’ve defined some state for a tab component. Developers familiar with Stimulus will notice that SPX components closely resemble how you might define values in controllers.

Default State

Let’s now elaborate on the previous definitions and provide some default values to state interfaces. This approach mirrors Stimulus, with differences in naming convention. In this example, we’ll specify a pre-defined set of disableTabs in the interface.

Persisted State

In addition to the above approaches, you may require persisted state values. Persisted states instruct SPX to preserve the state values between page navigations, thereby skipping state resets whenever a component disconnects.


Shared State

Shared state instructs SPX to maintain state across all instances of a component. Changes applied to shared state are incremental, and it can be controlled from multiple points within your web application.