Function yew::functional::use_state [−][src]
pub fn use_state<T, F>(init_fn: F) -> UseStateHandle<T> where
T: 'static,
F: FnOnce() -> T,
Expand description
This hook is used to manage state in a function component.
Example
#[function_component(UseState)]
fn state() -> Html {
let counter = use_state(|| 0);
let onclick = {
let counter = counter.clone();
Callback::from(move |_| counter.set(*counter + 1))
};
html! {
<div>
<button {onclick}>{ "Increment value" }</button>
<p>
<b>{ "Current value: " }</b>
{ *counter }
</p>
</div>
}
}