watch_debounced
A debounced version of watch
.
Demo
Usage
use leptos::*;
use leptos::logging::log;
use leptos_use::watch_debounced;
pub fn Demo() -> impl IntoView {
let (source, set_source) = create_signal(0);
watch_debounced(
move || source.get(),
move |_, _, _| {
log!("changed!");
},
500.0,
);
view! { }
}
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
).
use leptos::*;
use leptos::logging::log;
use leptos_use::{watch_debounced_with_options, WatchDebouncedOptions};
pub fn Demo() -> impl IntoView {
let (source, set_source) = create_signal(0);
watch_debounced_with_options(
move || source.get(),
move |_, _, _| {
log!("changed!");
},
500.0,
WatchDebouncedOptions::default().max_wait(Some(1000.0)),
);
view! { }
}
Recommended Reading
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.