Leptos-Use Guide

watch_pausable

Pausable watch.

Demo

Usage

use leptos::prelude::*;
use leptos::logging::log;
use leptos_use::{watch_pausable, WatchPausableReturn};

pub fn Demo() -> impl IntoView {
let (source, set_source) = 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"
   view! { }
}

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.

See also

  • leptos::watch

Feature

This function is only available if the crate feature watch_pausable is enabled

Types

Source

SourceDemoDocs