Function ambient_element::use_state

source ·
pub fn use_state<T: Clone + Debug + Send + 'static>(
    hooks: &mut Hooks<'_>,
    init: T
) -> (T, Setter<T>)
Expand description

Preserve state between rerenders.

The state can be mutated by the setter, which will re-render the origin Element.

Note: The new value set by the returned setter won’t be visible until the next re-render.

let (value, setter) = use_state(hooks,5);

setter(7);

println!("{value}"); // Prints 5