Function leptos_use::watch_debounced

source ·
pub fn watch_debounced<W, T, DFn, CFn>(
    deps: DFn,
    callback: CFn,
    ms: f64,
) -> impl Fn() + Clone
where DFn: Fn() -> W + 'static, CFn: Fn(&W, Option<&W>, Option<T>) -> T + Clone + 'static, W: Clone + 'static, T: Clone + 'static,
Expand description

A debounced version of watch.

§Demo

Link to Demo

§Usage

watch_debounced(
    move || source.get(),
    move |_, _, _| {
        log!("changed!");
    },
    500.0,
);

This really is only shorthand shorthand for watch_with_options(deps, callback, WatchOptions::default().debounce(ms)).

Please note that if the current component is cleaned up before the debounced callback is called, the debounced callback will not be called.

There’s also watch_debounced_with_options where you can specify the other watch options (except filter).

watch_debounced_with_options(
    move || source.get(),
    move |_, _, _| {
        log!("changed!");
    },
    500.0,
    WatchDebouncedOptions::default().max_wait(Some(1000.0)),
);

§Server-Side Rendering

On the server the callback will never be called except if you set immediate to true in which case the callback will be called exactly once.

§See also