Function leptos_use::watch_pausable
source · pub fn watch_pausable<W, T, DFn, CFn>(
deps: DFn,
callback: CFn
) -> WatchPausableReturn<impl Fn() + Clone, impl Fn() + Clone, impl Fn() + Clone>
Expand description
Pausable watch
.
§Demo
§Usage
let (source, set_source) = create_signal("foo".to_string());
let WatchPausableReturn {
stop,
pause,
resume,
..
} = watch_pausable(
move || source.get(),
|v, _, _| {
log!("Changed to {}", v);
},
);
set_source.set("bar".to_string()); // > "Changed to bar"
pause();
set_source.set("foobar".to_string()); // (nothing happens)
resume();
set_source.set("hello".to_string()); // > "Changed to hello"
There’s also watch_pausable_with_options
which takes the same options as watch
.
§Server-Side Rendering
On the server this works just fine except if you throttle or debounce in which case the callback
will never be called except if you set immediate
to true
in which case the callback will be
called exactly once.