watch!() { /* proc-macro */ }Expand description
The watch! macro for creating reactive side effects.
Watches one or more signals and executes a closure whenever any of them changes.
The closure is also executed once immediately with the current signal values
during initialisation. This initial execution is wrapped in a suppressed-update
scope so that any .set() calls inside the body do not trigger unnecessary
DynamicNode re-renders.
The number of signal expressions must match the number of closure parameters.
Each closure parameter receives the current value (via .get()) of the
corresponding signal.
ⓘ
let count = use_signal(|| 0_i32);
let name = use_signal(|| String::from("euv"));
watch!(count, name, |count_val, name_val| {
web_sys::console::log_1(&format!("count={}, name={}", count_val, name_val).into());
});