pub fn untrack<T>(fun: impl FnOnce() -> T) -> T
Expand description
Suspends reactive tracking while running the given function.
This can be used to isolate parts of the reactive graph from one another.
let (a, set_a) = signal(0);
let (b, set_b) = signal(0);
let c = Memo::new(move |_| {
// this memo will *only* update when `a` changes
a.get() + untrack(move || b.get())
});
assert_eq!(c.get(), 0);
set_a.set(1);
assert_eq!(c.get(), 1);
set_b.set(1);
// hasn't updated, because we untracked before reading b
assert_eq!(c.get(), 1);
set_a.set(2);
assert_eq!(c.get(), 3);