Function leptos_use::watch_throttled
source · pub fn watch_throttled<W, T, DFn, CFn>(
deps: DFn,
callback: CFn,
ms: f64
) -> impl Fn() + Clone
Expand description
A throttled version of [watch
].
§Demo
§Usage
watch_throttled(
move || source.get(),
move |_, _, _| {
log!("changed!");
},
500.0,
);
This really is only shorthand shorthand for watch_with_options(deps, callback, WatchOptions::default().throttle(ms))
.
Please note that if the current component is cleaned up before the throttled callback is called, the throttled callback will not be called.
There’s also watch_throttled_with_options
where you can specify the other watch options (except filter
).
watch_throttled_with_options(
move || source.get(),
move |_, _, _| {
log!("changed!");
},
500.0,
WatchThrottledOptions::default().leading(true).trailing(false),
);
§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.
§See also
- [
watch
] - [
watch_debounced
]