Function use_state

Source
pub fn use_state<T>(
    cc: HookBuilder,
    default_value: T,
) -> impl HookReturn<(T, Updater<T>)>
where T: Copy + Clone + 'static,
Expand description

Use a state. The given value will be the default.

The value should be Copy. If it is not, consider using use_state_from instead.

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, 3);