Mutable reactive state. This function takes an initial value and returns:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/marimo-team/marimo/llms.txt
Use this file to discover all available pages before exploring further.
- a getter function that reads the state value
- a setter function to set the state’s value
allow_self_loops=True.
Usage
Create state
Read the value
Update the state
Update based on current value
Synchronizing multiple UI elements
Signature
Parameters
Initial value of the state.
If
True, a cell that calls a state setter and also references its getter will be re-run. Defaults to False.Returns
tuple[State[T], Callable[[T], None]]
A tuple of (getter function, setter function). The getter function retrieves the state value; the setter function takes a new value or a function that updates the current value.
Important Notes
Never mutate the state directly. You should only change its value through its setter. You can use this function withUIElement on_change handlers to trigger side-effects when an element’s value is updated; however, you should prefer using marimo’s built-in reactive execution for interactive elements.