Function consecuit::hooks::use_state_from [−][src]
pub fn use_state_from<T, F>(
cc: HookBuilder,
default_from: F
) -> impl HookReturn<(T, Updater<T>)> where
T: Clone + 'static,
F: FnOnce() -> T,
Expand description
Use a state. The given closure will be used to create the initial value.
Returns the value in the state, and an Updater that can be used to update it.
Example:
let (cc, (age, set_age)) = cc.hook(use_state_from, || { rand::random::<i32>() });
Take a look at the counters example, for example on using this to create a counter.