pub fn use_toggle<'hook, T>(
default: T,
other: T,
) -> impl 'hook + Hook<Output = UseToggleHandle<T>>where
T: 'static + PartialEq + 'hook,
Expand description
This hook is used to manage toggle state in a function component.
§Example
use yew_hooks::prelude::*;
#[function_component(UseToggle)]
fn toggle() -> Html {
let toggle = use_toggle("Hello", "World");
let onclick = {
let toggle = toggle.clone();
Callback::from(move |_| toggle.toggle())
};
html! {
<div>
<button {onclick}>{ "Toggle" }</button>
<p>
<b>{ "Current value: " }</b>
{ *toggle }
</p>
</div>
}
}
§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_toggle<T>(default: T, other: T) -> UseToggleHandle<T>
where
T: 'static + PartialEq,
{
/* implementation omitted */
}