euv_ui/hook/use_boolean/fn.rs
1use super::*;
2
3/// Obtains the [`UseBoolean`] registered against the current hook context slot.
4///
5/// Behaves like `HookContext::use_hook` - the same `UseBoolean` is
6/// returned on every render at the same hook index, so the value
7/// survives re-renders.
8///
9/// The initial value is applied once, on the first render. Later
10/// renders never reset the value back to the initial one - use
11/// `set_value` to change it.
12///
13/// # Arguments
14///
15/// - `bool` - The value the toggle starts at.
16///
17/// # Returns
18///
19/// - `UseBoolean` - The toggle handle, with `get_value()` returning the
20/// reactive `Signal<bool>`.
21pub fn use_boolean(initial: bool) -> UseBoolean {
22 HookContext::use_hook(|| {
23 let handle: UseBoolean = UseBoolean::new();
24 handle.get_value().set(initial);
25 handle
26 })
27}