Skip to main content

state

Macro state 

Source
state!() { /* proc-macro */ }
Expand description

The state! macro for creating order-independent state.

This is the recommended way to create state in Telex. Unlike traditional hooks, state created with this macro can be used conditionally or in any order without causing panics.

Each macro invocation creates a unique anonymous type as the key, ensuring each call site gets its own independent state.

ยงExamples

Basic usage:

โ“˜
let count = state!(cx, || 0);

Safe in conditionals:

โ“˜
if show_counter {
    let count = state!(cx, || 0);  // This is safe!
}

Multiple independent states:

โ“˜
let name = state!(cx, || String::new());
let count = state!(cx, || 0);
let visible = state!(cx, || true);