Connecting Views
States can be connected to views.
Local State
State that shares the lifecycle of the attached component.
States with constructor values
state MyState(initialValue: number) -> {
value = initialValue;
mut increment -> $value++;
}
view SomeView ~ MyState(8) -> {
<div>
<span>total: {$value}</span>
<button onClick={$increment}>add</button>
</div>
}States without constructor values or with default values
state DefaultedState(initialValue: number = 0) -> { }
state SimpleState() -> { }
view SomeView ~ DefaultedState, SimpleState {
<div>
<span>total: {$value}</span>
<button onClick={$increment}>add</button>
</div>
}Contextual State
Contextual state allows for components to communicate implicitly through statically declared dependencies.
Object types can also be used to describe dependencies
This allows a component to be used in more generic scenarios.
Last updated
Was this helpful?