pub fn use_throttle_state<'hook, T, F>(
init_fn: F,
millis: u32,
) -> impl 'hook + Hook<Output = UseThrottleStateHandle<T>>where
T: 'static + 'hook,
F: FnOnce() -> T + 'hook,Expand description
A hook that throttles updating state, the state is only updated once every millis.
§Example
use yew_hooks::prelude::*;
#[function_component(ThrottleState)]
fn throttle_state() -> Html {
let state = use_throttle_state(|| 0, 2000);
let onclick = {
let state = state.clone();
Callback::from(move |_| state.set(*state + 1))
};
html! {
<>
<button {onclick}>{ "Click fast!" }</button>
<b>{ "State: " }</b> {*state}
</>
}
}§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_throttle_state<T, F>(init_fn: F, millis: u32) -> UseThrottleStateHandle<T>
where
T: 'static,
F: FnOnce() -> T,
{
/* implementation omitted */
}