State

SPX States are data references defined on both the DOM element and component level. State can be used to establish 2-way inferfacing, allowing data communication to and from view elements. SPX persists state in component, which means defintions are preserved between page navigations, skipping state resets whenever a component unmounts from the DOM.

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.