[−][src]Function comp_state::prelude::use_state
pub fn use_state<T: 'static + Clone, F: FnOnce() -> T>(
data_fn: F
) -> (T, StateAccess<T>)
Constructs a T and T accessor pair. T is stored keyed to the current topological context. The accessor always references this context therefore can you can set/update/ or get this T from anywhere.
If T has already been stored on subsequent revists, T will be a clone of the latest stored T.
Only one type per context can be stored in this way.
Examples
let (my_string, my_string_access) = use_state(|| "foo".to_string()); ... ... // Maybe in a Callback... my_string_access.set("bar")
This stores a string "foo" in the current topological context, which is later set to "bar", in some other part of the program.