State provides local interpolation values to its children. Children resolve {{ }} template expressions against the State’s values first, falling through to parent scopes and then global state.
This is useful when you want to inject data into a subtree without polluting global state or duplicating values across multiple props.
Basic Usage
How It Works
Any kwargs that aren’t base component fields (css_class, etc.) are collected into the state dict. You can also pass a dict positionally:
Equivalent Forms
State node with a state object.
Nested State
State components can nest. Inner values shadow outer ones for the same key, and children see the merged context: The firstText renders “Don’t Panic, Arthur”. The second renders “Don’t Panic, Ford” — the inner State shadows name but inherits greeting.
With ForEach
State works well alongside ForEach for providing extra context to iterated templates:API Reference
Protocol Reference
State